1

我需要OAuth在我的 Android 应用程序中使用协议。我决定使用android-oauth-client。在我的build.gradle文件中,我有:

dependencies {        
    compile 'com.android.support:appcompat-v7:21.0.0'
    compile 'com.wu-man:android-oauth-client:0.0.3'    
}

使用 gradle 文件同步项目工作正常,但是当我尝试构建我的应用程序时,出现了问题:

错误:任务“:app:dexDebug”执行失败。com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_51\bin\java.exe'' 完成非零退出值 2

我发现我应该尝试multiDexEnabled truedefaultConfig. build.gradle第一个问题解决了,但还有一个问题:

错误:任务“:app:packageAllDebugClassesForMultiDex”执行失败。java.util.zip.ZipException:重复条目:android/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoIcsImpl.class

我不知道如何修复它以及如何构建我的项目。你能帮我吗?提前致谢。

4

1 回答 1

7

support-v4传递依赖被添加了两次。您可以使用依赖项任务或依赖项洞察报告来验证它:

MacBook-Pro:demo alex$ ./gradlew app:dependencies --configuration compile

或者:

MacBook-Pro:demo alex$ ./gradlew app:dependencyInsight --configuration compile --dependency support-v4

其中demo是项目的根目录。编译配置的输出将是:

compile - Classpath for compiling the main sources.
+--- com.android.support:appcompat-v7:21.0.0
|    \--- com.android.support:support-v4:21.0.0
|         \--- com.android.support:support-annotations:21.0.0
\--- com.wu-man:android-oauth-client:0.0.3
     +--- com.google.oauth-client:google-oauth-client-java6:1.15.0-rc
     |    \--- com.google.oauth-client:google-oauth-client:1.15.0-rc
     |         +--- com.google.http-client:google-http-client:1.15.0-rc
     |         |    \--- com.google.code.findbugs:jsr305:1.3.9
     |         \--- com.google.code.findbugs:jsr305:1.3.9
     +--- com.google.http-client:google-http-client-jackson:1.15.0-rc
     |    +--- com.google.http-client:google-http-client:1.15.0-rc (*)
     |    \--- org.codehaus.jackson:jackson-core-asl:1.9.11
     +--- com.google.android:support-v4:r7
     \--- com.google.api-client:google-api-client-android:1.15.0-rc
          +--- com.google.api-client:google-api-client:1.15.0-rc
          |    \--- com.google.oauth-client:google-oauth-client:1.15.0-rc (*)
          \--- com.google.http-client:google-http-client-android:1.15.0-rc
               \--- com.google.http-client:google-http-client:1.15.0-rc (*)

依赖洞察报告的输出将是:

:app:dependencyInsight
com.android.support:support-v4:21.0.0
\--- com.android.support:appcompat-v7:21.0.0
     \--- compile

com.google.android:support-v4:r7
\--- com.wu-man:android-oauth-client:0.0.3
     \--- compile


请注意,appcompat-v7android-oauth-client都依赖于support-v4。您可以通过排除 android-oauth-client 的依赖项轻松解决它:

dependencies {
    compile 'com.android.support:appcompat-v7:21.0.0'
    compile ('com.wu-man:android-oauth-client:0.0.3') {
        exclude group: 'com.google.android', module: 'support-v4'
    }
}
于 2015-08-17T11:20:37.330 回答