OAuth的在Android应用程序 [英] OAuth in Android application

查看:284
本文介绍了OAuth的在Android应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用的OAuth 协议在我的Andr​​oid应用程序。我决定使用 Android系统的OAuth客户端。在我的 build.gradle 文件我有:

I need to use OAuth protocol in my Android application. I decided to use android-oauth-client. In my build.gradle file I have:

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

同步项目摇篮文件工作正常,但是当我尝试建立我的应用程序,有一个问题:

Sync project with gradle files works fine, but when I try to build my application, there is a problem:

错误:未能执行任务:应用程序:dexDebug。   com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:处理'命令'C:\ Program Files文件\的Java \ jdk1.7.0_51 \斌\ java.exe的''与非完零退出值2

Error:Execution failed for task ':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'' finished with non-zero exit value 2

我发现我应该尝试添加 multiDexEnabled真正构建 defaultConfig 部分.gradle 。第一个问题就解决了​​,但有另一个问题:

I found that I should try to add multiDexEnabled true in defaultConfig section in build.gradle. The first problem is solved, but there is another one:

错误:未能执行任务:应用程序:packageAllDebugClassesForMultiDex。   java.util.zip.ZipException:重复的条目: android/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoIcsImpl.class

Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'. java.util.zip.ZipException: duplicate entry: android/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoIcsImpl.class

我不知道我该如何解决?如何建立我的项目。你能帮助我,好吗?先谢谢了。

I have no idea how can I fix it and how can I build my project. Can you help me, please? Thanks in advance.

推荐答案

支持-V4 传递依赖正在增加两倍。您可以使用相关性任务或依赖洞察报告验证:

The support-v4 transitive dependency is being added twice. You can verify it using either dependencies task or dependency insight report:

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

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

其中的演示的是项目的根目录。对于编译配置的输出将是:

Where demo is the root directory of your project. The output for compile configuration will be:

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 (*)

和相关见解的报告结果应该是:

And the output of dependency insight report will be:

: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-V7 Android的OAuth的客户端依赖于支持-V4 。您可以通过排除Android的支持OAuth客户的依赖很容易解决这个问题:


Note that both appcompat-v7 and android-oauth-client depend on support-v4. You can easily solve it by excluding the android-oauth-client's dependency:

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'
    }
}

这篇关于OAuth的在Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆