2016-11-22 82 views
2

我正在開發一個Android應用程序,爲期4周。我正在爲Skype for Business - 適用於Android的應用程序SDK製作應用程序 - 預覽(https://www.microsoft.com/en-us/download/details.aspx?id=51961)。該應用已準備好進行Alpha測試,因此我想將APK發佈到Google Play商店中。我需要有一個APK文件,才能將其上傳到Google Play開發控制檯。Android Studio不會構建我的APK?

如果我嘗試生成APK(頂部菜單>生成>生成APK),我得到了以下錯誤消息:

com.android.build.api.transform.TransformException:java.util.zip .ZipException:重複條目:okhttp3/Address.class

但最奇怪的是,如果我在調試模式下運行應用程序,它工作得很好。

也許我的gradle構建文件有問題嗎?

android { 

compileSdkVersion Integer.parseInt(COMPILE_SDK_VERSION) 
buildToolsVersion BUILD_TOOLS_VERSION 

defaultConfig { 
    applicationId "com.microsoft.office.sfb.sfbdemo" 
    minSdkVersion Integer.parseInt(MIN_SDK_VERSION) 
    targetSdkVersion Integer.parseInt(TARGET_SDK_VERSION) 
    versionCode 1 
    versionName "1.0" 
    multiDexEnabled true 
} 

compileOptions { 
    sourceCompatibility JavaVersion.VERSION_1_7 
    targetCompatibility JavaVersion.VERSION_1_7 
} 

buildTypes { 
    debug { 
     minifyEnabled false 
     debuggable true 
     jniDebuggable true 
    } 
    release { 
     debuggable false 
    } 
} 

packagingOptions { 
    exclude 'META-INF/maven/com.squareup.okhttp3/okhttp/pom.properties' 
    exclude 'META-INF/maven/com.squareup.okhttp3/okhttp/pom.xml' 
    exclude 'META-INF/maven/com.squareup.okio/okio/pom.properties' 
    exclude 'META-INF/maven/com.squareup.okio/okio/pom.xml' 
    exclude 'META-INF/DEPENDENCIES' 
    exclude 'META-INF/LICENSE.txt' 
    exclude 'META-INF/NOTICE.txt' 
    exclude 'META-INF/NOTICE' 
    exclude 'META-INF/LICENSE' 
    exclude 'META-INF/MSFTSIG.RSA' 
    exclude 'META-INF/BCKEY.DSA' 
    exclude 'META-INF/BCKEY.SF' 
    exclude 'META-INF/MSFTSIG.SF' 
} 

dexOptions { 
    preDexLibraries false 
    jumboMode true 
    incremental true 
    javaMaxHeapSize "4g" 
} 
} 

dependencies { 

    compile fileTree(include: ['*.jar'], dir: 'libs') 

    testCompile 'junit:junit:4.12' 

    compile(name: "libucmp", ext: 'aar') 
    compile(name: "platform", ext: 'aar') 
    compile(name: "injector", ext: 'aar') 
    compile(name: "SkypeForBusiness", ext: 'aar') 
    compile(name: "ucmp-enums", ext: 'aar') 
    compile(name: "TelemetryClient2", ext: 'aar') 
    compile(name: "TelemetryService", ext: 'aar') 
    compile(name: "android-database-sqlcipher", ext: 'aar') 

    compile "com.android.support:multidex:1.0.1" 
    compile 'com.google.code.gson:gson:2.6.2' 
    compile 'com.android.support:appcompat-v7:22.2.1' 
    compile 'com.android.support:design:22.2.1' 
    compile 'com.android.support:support-v4:22.2.1' 
    compile 'com.android.support:recyclerview-v7:22.2.1' 
    compile 'com.android.support:cardview-v7:22.2.1' 

    compile ('com.squareup.retrofit2:retrofit:2.1.0') { 
     exclude module: 'com.squareup.okio' 
    } 

    compile ('com.squareup.retrofit2:converter-gson:2.1.0') { 
     exclude module: 'com.squareup.okio' 
    } 
} 

Android Studio中的郵件列表:

Information:Gradle tasks [:sfbdemo:assembleDebug] 
:sfbdemo:preBuild UP-TO-DATE 
:sfbdemo:preDebugBuild UP-TO-DATE 
:sfbdemo:checkDebugManifest 
:sfbdemo:preReleaseBuild UP-TO-DATE 
:sfbdemo:prepareAndroidDatabaseSqlcipherLibrary UP-TO-DATE 
:sfbdemo:prepareComAndroidSupportAppcompatV72221Library UP-TO-DATE 
:sfbdemo:prepareComAndroidSupportCardviewV72221Library UP-TO-DATE 
:sfbdemo:prepareComAndroidSupportDesign2221Library UP-TO-DATE 
:sfbdemo:prepareComAndroidSupportMultidex101Library UP-TO-DATE 
:sfbdemo:prepareComAndroidSupportRecyclerviewV72221Library UP-TO-DATE 
:sfbdemo:prepareComAndroidSupportSupportV42221Library UP-TO-DATE 
:sfbdemo:prepareInjectorLibrary UP-TO-DATE 
:sfbdemo:prepareLibucmpLibrary UP-TO-DATE 
:sfbdemo:preparePlatformLibrary UP-TO-DATE 
:sfbdemo:prepareSkypeForBusinessLibrary UP-TO-DATE 
:sfbdemo:prepareTelemetryClient2Library UP-TO-DATE 
:sfbdemo:prepareTelemetryServiceLibrary UP-TO-DATE 
:sfbdemo:prepareUcmpEnumsLibrary UP-TO-DATE 
:sfbdemo:prepareDebugDependencies 
:sfbdemo:compileDebugAidl UP-TO-DATE 
:sfbdemo:compileDebugRenderscript UP-TO-DATE 
:sfbdemo:generateDebugBuildConfig UP-TO-DATE 
:sfbdemo:mergeDebugShaders UP-TO-DATE 
:sfbdemo:compileDebugShaders UP-TO-DATE 
:sfbdemo:generateDebugAssets UP-TO-DATE 
:sfbdemo:mergeDebugAssets UP-TO-DATE 
:sfbdemo:generateDebugResValues UP-TO-DATE 
:sfbdemo:generateDebugResources UP-TO-DATE 
:sfbdemo:mergeDebugResources UP-TO-DATE 
:sfbdemo:processDebugManifest UP-TO-DATE 
:sfbdemo:processDebugResources UP-TO-DATE 
:sfbdemo:generateDebugSources UP-TO-DATE 
:sfbdemo:incrementalDebugJavaCompilationSafeguard UP-TO-DATE 
:sfbdemo:compileDebugJavaWithJavac UP-TO-DATE 
:sfbdemo:compileDebugNdk UP-TO-DATE 
:sfbdemo:compileDebugSources UP-TO-DATE 
:sfbdemo:prePackageMarkerForDebug 
:sfbdemo:transformClassesWithJarMergingForDebug FAILED 
Error:Execution failed for task ':sfbdemo:transformClassesWithJarMergingForDebug'. 
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: okhttp3/Address.class 
Information:BUILD FAILED 
Information:Total time: 3.576 secs 
Information:1 error 
Information:0 warnings 
Information:See complete output in console 

我也運行gradle這個任務sfddemo:依賴關係,並構建了全成。但我仍然無法構建APK。

依賴性列表:

$ gradle :sfbdemo:dependencies 
Incremental java compilation is an incubating feature. 
:sfbdemo:dependencies 

------------------------------------------------------------ 
Project :sfbdemo 
------------------------------------------------------------ 

_debugAndroidTestApk - ## Internal use, do not manually configure ## 
\--- com.android.support:multidex-instrumentation:1.0.1 
    \--- com.android.support:multidex:1.0.1 

_debugAndroidTestCompile - ## Internal use, do not manually configure ## 
\--- com.android.support:multidex-instrumentation:1.0.1 
    \--- com.android.support:multidex:1.0.1 

_debugApk - ## Internal use, do not manually configure ## 
+--- com.android.support:multidex:1.0.1 
+--- :libucmp: 
+--- :platform: 
+--- :injector: 
+--- :SkypeForBusiness: 
+--- :ucmp-enums: 
+--- :TelemetryClient2: 
+--- :TelemetryService: 
+--- :android-database-sqlcipher: 
+--- com.google.code.gson:gson:2.6.2 -> 2.7 
+--- com.android.support:appcompat-v7:22.2.1 
| \--- com.android.support:support-v4:22.2.1 
|   \--- com.android.support:support-annotations:22.2.1 
+--- com.android.support:design:22.2.1 
| +--- com.android.support:appcompat-v7:22.2.1 (*) 
| \--- com.android.support:support-v4:22.2.1 (*) 
+--- com.android.support:support-v4:22.2.1 (*) 
+--- com.android.support:recyclerview-v7:22.2.1 
| +--- com.android.support:support-annotations:22.2.1 
| \--- com.android.support:support-v4:22.2.1 (*) 
+--- com.android.support:cardview-v7:22.2.1 
+--- com.squareup.retrofit2:retrofit:2.1.0 
| \--- com.squareup.okhttp3:okhttp:3.3.0 
|   \--- com.squareup.okio:okio:1.8.0 
\--- com.squareup.retrofit2:converter-gson:2.1.0 
    +--- com.squareup.retrofit2:retrofit:2.1.0 (*) 
    \--- com.google.code.gson:gson:2.7 

_debugCompile - ## Internal use, do not manually configure ## 
+--- com.android.support:multidex:1.0.1 
+--- :libucmp: 
+--- :platform: 
+--- :injector: 
+--- :SkypeForBusiness: 
+--- :ucmp-enums: 
+--- :TelemetryClient2: 
+--- :TelemetryService: 
+--- :android-database-sqlcipher: 
+--- com.google.code.gson:gson:2.6.2 -> 2.7 
+--- com.android.support:appcompat-v7:22.2.1 
| \--- com.android.support:support-v4:22.2.1 
|   \--- com.android.support:support-annotations:22.2.1 
+--- com.android.support:design:22.2.1 
| +--- com.android.support:appcompat-v7:22.2.1 (*) 
| \--- com.android.support:support-v4:22.2.1 (*) 
+--- com.android.support:support-v4:22.2.1 (*) 
+--- com.android.support:recyclerview-v7:22.2.1 
| +--- com.android.support:support-annotations:22.2.1 
| \--- com.android.support:support-v4:22.2.1 (*) 
+--- com.android.support:cardview-v7:22.2.1 
+--- com.squareup.retrofit2:retrofit:2.1.0 
| \--- com.squareup.okhttp3:okhttp:3.3.0 
|   \--- com.squareup.okio:okio:1.8.0 
\--- com.squareup.retrofit2:converter-gson:2.1.0 
    +--- com.squareup.retrofit2:retrofit:2.1.0 (*) 
    \--- com.google.code.gson:gson:2.7 

_debugUnitTestApk - ## Internal use, do not manually configure ## 
\--- junit:junit:4.12 
    \--- org.hamcrest:hamcrest-core:1.3 

_debugUnitTestCompile - ## Internal use, do not manually configure ## 
\--- junit:junit:4.12 
    \--- org.hamcrest:hamcrest-core:1.3 

_releaseApk - ## Internal use, do not manually configure ## 
+--- com.android.support:multidex:1.0.1 
+--- :libucmp: 
+--- :platform: 
+--- :injector: 
+--- :SkypeForBusiness: 
+--- :ucmp-enums: 
+--- :TelemetryClient2: 
+--- :TelemetryService: 
+--- :android-database-sqlcipher: 
+--- com.google.code.gson:gson:2.6.2 -> 2.7 
+--- com.android.support:appcompat-v7:22.2.1 
| \--- com.android.support:support-v4:22.2.1 
|   \--- com.android.support:support-annotations:22.2.1 
+--- com.android.support:design:22.2.1 
| +--- com.android.support:appcompat-v7:22.2.1 (*) 
| \--- com.android.support:support-v4:22.2.1 (*) 
+--- com.android.support:support-v4:22.2.1 (*) 
+--- com.android.support:recyclerview-v7:22.2.1 
| +--- com.android.support:support-annotations:22.2.1 
| \--- com.android.support:support-v4:22.2.1 (*) 
+--- com.android.support:cardview-v7:22.2.1 
+--- com.squareup.retrofit2:retrofit:2.1.0 
| \--- com.squareup.okhttp3:okhttp:3.3.0 
|   \--- com.squareup.okio:okio:1.8.0 
\--- com.squareup.retrofit2:converter-gson:2.1.0 
    +--- com.squareup.retrofit2:retrofit:2.1.0 (*) 
    \--- com.google.code.gson:gson:2.7 

_releaseCompile - ## Internal use, do not manually configure ## 
+--- com.android.support:multidex:1.0.1 
+--- :libucmp: 
+--- :platform: 
+--- :injector: 
+--- :SkypeForBusiness: 
+--- :ucmp-enums: 
+--- :TelemetryClient2: 
+--- :TelemetryService: 
+--- :android-database-sqlcipher: 
+--- com.google.code.gson:gson:2.6.2 -> 2.7 
+--- com.android.support:appcompat-v7:22.2.1 
| \--- com.android.support:support-v4:22.2.1 
|   \--- com.android.support:support-annotations:22.2.1 
+--- com.android.support:design:22.2.1 
| +--- com.android.support:appcompat-v7:22.2.1 (*) 
| \--- com.android.support:support-v4:22.2.1 (*) 
+--- com.android.support:support-v4:22.2.1 (*) 
+--- com.android.support:recyclerview-v7:22.2.1 
| +--- com.android.support:support-annotations:22.2.1 
| \--- com.android.support:support-v4:22.2.1 (*) 
+--- com.android.support:cardview-v7:22.2.1 
+--- com.squareup.retrofit2:retrofit:2.1.0 
| \--- com.squareup.okhttp3:okhttp:3.3.0 
|   \--- com.squareup.okio:okio:1.8.0 
\--- com.squareup.retrofit2:converter-gson:2.1.0 
    +--- com.squareup.retrofit2:retrofit:2.1.0 (*) 
    \--- com.google.code.gson:gson:2.7 

_releaseUnitTestApk - ## Internal use, do not manually configure ## 
\--- junit:junit:4.12 
    \--- org.hamcrest:hamcrest-core:1.3 

_releaseUnitTestCompile - ## Internal use, do not manually configure ## 
\--- junit:junit:4.12 
    \--- org.hamcrest:hamcrest-core:1.3 

androidJacocoAgent - The Jacoco agent to use to get coverage data. 
Download https://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/0.7.6.201602                                                180812/org.jacoco.agent-0.7.6.201602180812.pom 
\--- org.jacoco:org.jacoco.agent:0.7.6.201602180812 

androidJacocoAnt - The Jacoco ant tasks to use to get execute Gradle tasks. 
Download https://repo1.maven.org/maven2/org/jacoco/org.jacoco.ant/0.7.6.20160218                                                0812/org.jacoco.ant-0.7.6.201602180812.pom 
Download https://repo1.maven.org/maven2/org/jacoco/org.jacoco.report/0.7.6.20160                                                2180812/org.jacoco.report-0.7.6.201602180812.pom 
\--- org.jacoco:org.jacoco.ant:0.7.6.201602180812 
    +--- org.jacoco:org.jacoco.core:0.7.6.201602180812 
    | \--- org.ow2.asm:asm-debug-all:5.0.4 
    +--- org.jacoco:org.jacoco.report:0.7.6.201602180812 
    | +--- org.jacoco:org.jacoco.core:0.7.6.201602180812 (*) 
    | \--- org.ow2.asm:asm-debug-all:5.0.4 
    \--- org.jacoco:org.jacoco.agent:0.7.6.201602180812 

androidTestApk - Classpath packaged with the compiled 'androidTest' classes. 
No dependencies 

androidTestCompile - Classpath for compiling the androidTest sources. 
No dependencies 

androidTestProvided - Classpath for only compiling the androidTest sources. 
No dependencies 

androidTestWearApp - Link to a wear app to embed for object 'androidTest'. 
No dependencies 

apk - Classpath packaged with the compiled 'main' classes. 
No dependencies 

archives - Configuration for archive artifacts. 
No dependencies 

compile - Classpath for compiling the main sources. 
+--- :libucmp: 
+--- :platform: 
+--- :injector: 
+--- :SkypeForBusiness: 
+--- :ucmp-enums: 
+--- :TelemetryClient2: 
+--- :TelemetryService: 
+--- :android-database-sqlcipher: 
+--- com.android.support:multidex:1.0.1 
+--- com.google.code.gson:gson:2.6.2 -> 2.7 
+--- com.android.support:appcompat-v7:22.2.1 
| \--- com.android.support:support-v4:22.2.1 
|   \--- com.android.support:support-annotations:22.2.1 
+--- com.android.support:design:22.2.1 
| +--- com.android.support:appcompat-v7:22.2.1 (*) 
| \--- com.android.support:support-v4:22.2.1 (*) 
+--- com.android.support:support-v4:22.2.1 (*) 
+--- com.android.support:recyclerview-v7:22.2.1 
| +--- com.android.support:support-annotations:22.2.1 
| \--- com.android.support:support-v4:22.2.1 (*) 
+--- com.android.support:cardview-v7:22.2.1 
+--- com.squareup.retrofit2:retrofit:2.1.0 
| \--- com.squareup.okhttp3:okhttp:3.3.0 
|   \--- com.squareup.okio:okio:1.8.0 
\--- com.squareup.retrofit2:converter-gson:2.1.0 
    +--- com.squareup.retrofit2:retrofit:2.1.0 (*) 
    \--- com.google.code.gson:gson:2.7 

debugApk - Classpath packaged with the compiled 'debug' classes. 
No dependencies 

debugCompile - Classpath for compiling the debug sources. 
No dependencies 

debugProvided - Classpath for only compiling the debug sources. 
No dependencies 

debugWearApp - Link to a wear app to embed for object 'debug'. 
No dependencies 

default - Configuration for default artifacts. 
No dependencies 

default-mapping - Configuration for default mapping artifacts. 
No dependencies 

default-metadata - Metadata for the produced APKs. 
No dependencies 

findbugs - The FindBugs libraries to be used for this project. 
No dependencies 

findbugsPlugins - The FindBugs plugins to be used for this project. 
No dependencies 

provided - Classpath for only compiling the main sources. 
No dependencies 

releaseApk - Classpath packaged with the compiled 'release' classes. 
No dependencies 

releaseCompile - Classpath for compiling the release sources. 
No dependencies 

releaseProvided - Classpath for only compiling the release sources. 
No dependencies 

releaseWearApp - Link to a wear app to embed for object 'release'. 
No dependencies 

testApk - Classpath packaged with the compiled 'test' classes. 
No dependencies 

testCompile - Classpath for compiling the test sources. 
\--- junit:junit:4.12 
    \--- org.hamcrest:hamcrest-core:1.3 

testDebugApk - Classpath packaged with the compiled 'testDebug' classes. 
No dependencies 

testDebugCompile - Classpath for compiling the testDebug sources. 
No dependencies 

testDebugProvided - Classpath for only compiling the testDebug sources. 
No dependencies 

testDebugWearApp - Link to a wear app to embed for object 'testDebug'. 
No dependencies 

testProvided - Classpath for only compiling the test sources. 
No dependencies 

testReleaseApk - Classpath packaged with the compiled 'testRelease' classes. 
No dependencies 

testReleaseCompile - Classpath for compiling the testRelease sources. 
No dependencies 

testReleaseProvided - Classpath for only compiling the testRelease sources. 
No dependencies 

testReleaseWearApp - Link to a wear app to embed for object 'testRelease'. 
No dependencies 

testWearApp - Link to a wear app to embed for object 'test'. 
No dependencies 

wearApp - Link to a wear app to embed for object 'main'. 
No dependencies 

BUILD SUCCESSFUL 

Total time: 4.811 secs 
+0

使用compile'c​​om.squareup.retrofit2:retrofit:2.1.0', compile'c​​om.squareup.retrofit2:converter-gson:2.1.0'並刪除packagingOptions {...}前兩行 – Vadivel

+0

你可以發佈完整的日誌嗎? – Raghavendra

+2

運行gradle任務':app:dependencies'來查看重複來自何處。 –

回答

0

我終於找到了解決我的問題。在互聯網上搜索了很久之後,我找到了以下解決方案。我把每個'編譯'行放在註釋中,然後我重建項目,看看是否一切正常。

我不斷重複這個過程,直到我發現哪一段代碼導致了這個問題。我發現下面這行代碼引起了這個問題:

compile(name: "platform", ext: 'aar') 

我希望這可以幫助你,解決你自己的問題。 :)