com.android.dex.DexException given when trying to integrate Youtube Data API into android app

心不动则不痛 提交于 2019-12-25 09:58:40

问题


When I try to integrate Youtube DATA Api functionality into my app, I finally managed to resolve all errors. But when I run the project, it gives me the following error:

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)

My build.gradle file is as follows:

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

I have looked at so many examples here but I am unable to resolve this error. If I set

multidexenabled true

In the Gradle file this error vanishes but I get another error

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

回答1:


The problem is

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

Do you really need in your app all Google Play Services API? You can just integrate what you actually need. Follow the instruction here - Section "Selectively compiling APIs into your executable"




回答2:


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

It should work in this way and you won't need the

multidexenabled true

anymore.



来源:https://stackoverflow.com/questions/33975264/com-android-dex-dexexception-given-when-trying-to-integrate-youtube-data-api-int

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!