尝试将Youtube Data API集成到Android应用程序时给出的com.android.dex.DexException

时间:2015-11-28 19:03:57

标签: android youtube youtube-data-api android-youtube-api android-multidex

当我尝试将Youtube DATA Api功能集成到我的应用程序中时,我终于设法解决了所有错误。但是当我运行该项目时,它会给我以下错误:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/api/client/auth/oauth/AbstractOAuthGetToken;
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
    at com.android.dx.command.dexer.Main.run(Main.java:246)
    at com.android.dx.command.dexer.Main.main(Main.java:215)
    at com.android.dx.command.Main.main(Main.java:106)

我的build.gradle文件如下:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "wheresapp.iiitb.com.wheresapp"
    minSdkVersion 15
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}


buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),   'proguard-rules.pro'
    }
}
}

dependencies {
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:support-v4:21.0.0'
compile 'com.google.android.gms:play-services:+'
compile 'com.google.apis:google-api-services-youtube:v3-rev152-1.21.0'
compile files('libs/twitter4j-core-4.0.1.jar')
compile files('libs/api-1.3.jar')
compile files('libs/json-simple.jar')
compile files('libs/google-oauth-client-1.16.0-rc.jar')
compile files('libs/google-oauth-client-jetty-1.11.0-beta.jar')
compile files('libs/google-oauth-client-java6-1.11.0-beta.jar')
}

我在这里看了很多例子但是我无法解决这个错误。如果我设置

multidexenabled true

在Gradle文件中,此错误消失但我收到另一个错误

java.util.zip.ZipException: duplicate entry: com/google/api/client/auth/oauth/package-info.class

2 个答案:

答案 0 :(得分:0)

问题是

compile 'com.google.android.gms:play-services:+'

您真的需要在您的应用中使用所有Google Play服务API吗? 您可以整合实际需要的内容。按照说明here - “将API选择性地编译到可执行文件”部分

答案 1 :(得分:0)

dependencies {
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.google.android.gms:play-services-maps:8.3.0'
compile 'com.google.apis:google-api-services-youtube:v3-rev152-1.21.0'
compile files('libs/twitter4j-core-4.0.1.jar')
compile files('libs/api-1.3.jar')
compile files('libs/json-simple.jar')
compile files('libs/google-oauth-client-1.16.0-rc.jar')
compile files('libs/google-oauth-client-jetty-1.11.0-beta.jar')
compile files('libs/google-oauth-client-java6-1.11.0-beta.jar')
}

它应该以这种方式工作,你不会需要

multidexenabled true

了。