Android Studio不会构建我的APK?

时间:2016-11-22 12:39:18

标签: java android android-studio gradle duplicates

我现在正在开发Android应用程序4周。我正在使用Skype for Business制作应用程序 - 适用于Android的App SDK - 预览(https://www.microsoft.com/en-us/download/details.aspx?id=51961)。该应用已准备好进行Alpha测试,因此我想在Google Play商店中发布APK。我需要有一个APK文件,才能将其上传到Google Play开发者控制台。

如果我尝试构建APK(Topmenu> Build> Build 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:dependencies,构建成功。但我仍然无法构建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

1 个答案:

答案 0 :(得分:0)

我终于找到了我的问题的解决方案。经过长时间的互联网搜索,我找到了以下解决方案。我把每个'编译'在评论中排队然后我重建项目,看看是否一切正常。

我一直在重复这个过程,直到找到导致问题的代码段。我发现以下代码行导致了问题:

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

我希望这可以帮助您解决自己的问题。 :)