我的理解是不止一次包含了一些库。问题是哪一个以及如何避免这种情况?
多次包含的疑似图书馆:
Android支持库。
我的尝试:
使用以下方法之一将其排除在主模块的Gradle构建脚本中:
方法#1:使用“配置”块:
configurations {
// to avoid double inclusion of support libraries
all*.exclude group: 'com.android.support', module: 'support-v4'
}
结果:支持库似乎完全被排除在项目中==>找不到类的问题,例如
cannot access FragmentActivity
public class AccountInfoFragment extends SherlockFragment implements DataLoadedCallback<AccountPO>,DialogInterface.OnClickListener{
^
class file for android.support.v4.app.FragmentActivity not found
方法#2:排除每个库的支持库 结果:问题仍然存在
============================
错误的完整堆栈跟踪:
Error:Gradle: Execution failed for task ':myapp:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Users/Eric/android-sdk/build-tools/20.0.0/dx --dex --output /Users/Eric/tmp/myapp/android/myapp/build/intermediates/dex/debug /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/achartengine-1.1.0-7b47dc124cf34522f2e00089bcce20da1d9daafb.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/bolts-android-1.1.2-1b7811ba358dc7261c04da44cffff27dc19a95bf.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/butterknife-6.0.0-082df546717f9c6d67265ed2604a6e3f41c72433.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/classes-0cac1f6067badf2d1a4d82a980533915dbf98e06.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/classes-142f671af697f6b9cba92b14354ee4300ae51e78.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/classes-1e46bc8a7eb72e7727956d5e4352924ceb2b77a1.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/classes-2c99dae7d9219c15273149d0d35ba0b1f9a13be5.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/classes-48179d4374e2a25c67fea5ff71940fdfa99c61af.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/classes-5183a95913a34be595f3376ba556e27844076538.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/classes-6239731b5893bbcac7b1f4fc00df9518ec99637e.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/classes-9fba0552287b788dec5e8eb7c445da4f8436284e.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/classes-d86676a0689fbe4db96155cf7fa3df07e0b92607.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/classes-df5e5215cac30fe94844ee6599f93ad546c972e9.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/google-api-client-1.19.0-5a21a128d4462f2c5855dfff5449401b40497140.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/google-api-services-youtube-v3-rev120-1.19.0-9ac8e0973005ba61bbc204b23361c6c6da738b15.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/google-http-client-1.19.0-7c0204c696118dd85912cda4299a80e7d78cdb01.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/google-http-client-jackson2-1.19.0-614a0de809cae5a131374375fed96d5690c14406.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/google-oauth-client-1.19.0-912669bfd391aae62209d0888c1253a88d580884.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/gson-2.2.4-57ce5e3c7d648a64a73b4451cf3aa3791012f40c.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/guava-jdk5-13.0-06c5cb09cd942dfb26581195ae6fe876a835b72e.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/internal_impl-21.0.2-214aff042b70e000fd89d9989b4a222cb0e76d35.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/internal_impl-21.0.2-9dd6ca746d46a7622f5db326e40a2140066d8202.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/jackson-core-2.1.3-7aed478d80f48350038b4c88f157afa4fe4f0444.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/jsr305-1.3.9-ff9aa60162778ae9cafa0fd673bd873256924307.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/support-annotations-21.0.2-ef4b81549522b9e9e235cf8bc8a048c6787daa07.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/universal-image-loader-1.9.3-d8f5630239430ef645489ff77450683807cdd3a9.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/pre-dexed/debug/YouTubeAndroidPlayerApi-070374576a0bdf40ef3d80ff2e993e0863558c69.jar /Users/Eric/tmp/myapp/android/myapp/build/intermediates/classes/debug
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: method ID not in [0, 0xffff]: 65536
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:501)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:276)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:490)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:167)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
我可以看到internal_impl
出现两次!
============================
按照方法#2,我的主模块的build.gradle如下:
apply plugin: 'android'
buildscript {
repositories {
mavenCentral()
}
}
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
lintOptions {
abortOnError false
}
defaultConfig {
applicationId "com.xyz"
minSdkVersion 14
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
// compile 'com.android.support:support-v13:+'
compile 'com.google.android.gms:play-services:+'
compile (project(':sherlockNavigationDrawer')) {
exclude group: 'com.android.support', module: 'support-v13'
}
compile (project(':facebookSDK')) {
exclude group: 'com.android.support', module: 'support-v13'
}
compile (project(':myLibrary')) {
exclude group: 'com.android.support', module: 'support-v13'
exclude group: 'com.actionbarsherlock', module: 'actionbarsherlock'
}
compile (project(':viewPagerLibrary')) {
exclude group: 'com.android.support', module: 'support-v13'
}
compile 'org.apmem.tools:layouts:1.5@aar'
compile 'com.github.amlcurran.showcaseview:library:5.0.0'
compile 'com.jakewharton:butterknife:6.0.0'
// compile 'com.android.support:support-v13:21.0.0'
compile 'com.google.apis:google-api-services-youtube:v3-rev120-1.19.0'
compile files('libs/achartengine-1.1.0.jar')
compile files('libs/YouTubeAndroidPlayerApi.jar')
}
当我跑./gradlew -q dependencies myapp:dependencies
时,我得到以下内容(没有重复):
_debugApk - ## Internal use, do not manually configure ##
+--- project :sherlockNavigationDrawer
| \--- com.actionbarsherlock:actionbarsherlock:4.4.0
+--- project :facebookSDK
+--- project :myLibrary
| +--- com.google.code.gson:gson:2.2.4
| \--- com.nostra13.universalimageloader:universal-image-loader:1.9.3
+--- project :viewPagerLibrary
+--- org.apmem.tools:layouts:1.5
+--- com.github.amlcurran.showcaseview:library:5.0.0
+--- com.jakewharton:butterknife:6.0.0
+--- com.google.android.gms:play-services:+ -> 6.5.87
| \--- com.android.support:support-v4:21.0.0
| \--- com.android.support:support-annotations:21.0.0
\--- com.google.apis:google-api-services-youtube:v3-rev120-1.19.0
\--- com.google.api-client:google-api-client:1.19.0
+--- com.google.oauth-client:google-oauth-client:1.19.0
| +--- com.google.http-client:google-http-client:1.19.0
| | +--- com.google.code.findbugs:jsr305:1.3.9
| | \--- org.apache.httpcomponents:httpclient:4.0.1
| | +--- org.apache.httpcomponents:httpcore:4.0.1
| | +--- commons-logging:commons-logging:1.1.1
| | \--- commons-codec:commons-codec:1.3
| \--- com.google.code.findbugs:jsr305:1.3.9
+--- com.google.http-client:google-http-client-jackson2:1.19.0
| +--- com.google.http-client:google-http-client:1.19.0 (*)
| \--- com.fasterxml.jackson.core:jackson-core:2.1.3
\--- com.google.guava:guava-jdk5:13.0
./gradlew -q dependencies myapp:dependencies
没有任何exclude
的原始结果:
_debugApk - ## Internal use, do not manually configure ##
+--- com.android.support:multidex:1.0.0 -> 1.0.1
+--- com.android.support:multidex:1.0.+ -> 1.0.1
+--- project :sherlockNavigationDrawer
| +--- com.actionbarsherlock:actionbarsherlock:4.4.0
| \--- com.android.support:support-v13:+ -> 21.0.3
| \--- com.android.support:support-v4:21.0.3
| \--- com.android.support:support-annotations:21.0.3
+--- project :facebookSDK
| \--- com.android.support:support-v13:+ -> 21.0.3 (*)
+--- project :myLibrary
| +--- com.android.support:support-v13:+ -> 21.0.3 (*)
| +--- com.google.code.gson:gson:2.2.4
| +--- com.actionbarsherlock:actionbarsherlock:4.4.0
| \--- com.nostra13.universalimageloader:universal-image-loader:1.9.3
+--- project :viewPagerLibrary
| \--- com.android.support:support-v13:+ -> 21.0.3 (*)
+--- org.apmem.tools:layouts:1.5
+--- com.github.amlcurran.showcaseview:library:5.0.0
+--- com.jakewharton:butterknife:6.0.0
+--- com.google.android.gms:play-services:+ -> 6.5.87
| \--- com.android.support:support-v4:21.0.0 -> 21.0.3 (*)
+--- com.android.support:support-v13:21.0.0 -> 21.0.3 (*)
\--- com.google.apis:google-api-services-youtube:v3-rev120-1.19.0
\--- com.google.api-client:google-api-client:1.19.0
+--- com.google.oauth-client:google-oauth-client:1.19.0
| +--- com.google.http-client:google-http-client:1.19.0
| | +--- com.google.code.findbugs:jsr305:1.3.9
| | \--- org.apache.httpcomponents:httpclient:4.0.1
| | +--- org.apache.httpcomponents:httpcore:4.0.1
| | +--- commons-logging:commons-logging:1.1.1
| | \--- commons-codec:commons-codec:1.3
| \--- com.google.code.findbugs:jsr305:1.3.9
+--- com.google.http-client:google-http-client-jackson2:1.19.0
| +--- com.google.http-client:google-http-client:1.19.0 (*)
| \--- com.fasterxml.jackson.core:jackson-core:2.1.3
\--- com.google.guava:guava-jdk5:13.0
_debugCompile - ## Internal use, do not manually configure ##
+--- com.android.support:multidex:1.0.0 -> 1.0.1
+--- com.android.support:multidex:1.0.+ -> 1.0.1
+--- project :sherlockNavigationDrawer
| +--- com.actionbarsherlock:actionbarsherlock:4.4.0
| \--- com.android.support:support-v13:+ -> 21.0.3
| \--- com.android.support:support-v4:21.0.3
| \--- com.android.support:support-annotations:21.0.3
+--- project :facebookSDK
| \--- com.android.support:support-v13:+ -> 21.0.3 (*)
+--- project :myLibrary
| +--- com.android.support:support-v13:+ -> 21.0.3 (*)
| +--- com.google.code.gson:gson:2.2.4
| +--- com.actionbarsherlock:actionbarsherlock:4.4.0
| \--- com.nostra13.universalimageloader:universal-image-loader:1.9.3
+--- project :viewPagerLibrary
| \--- com.android.support:support-v13:+ -> 21.0.3 (*)
+--- org.apmem.tools:layouts:1.5
+--- com.github.amlcurran.showcaseview:library:5.0.0
+--- com.jakewharton:butterknife:6.0.0
+--- com.google.android.gms:play-services:+ -> 6.5.87
| \--- com.android.support:support-v4:21.0.0 -> 21.0.3 (*)
+--- com.android.support:support-v13:21.0.0 -> 21.0.3 (*)
\--- com.google.apis:google-api-services-youtube:v3-rev120-1.19.0
\--- com.google.api-client:google-api-client:1.19.0
+--- com.google.oauth-client:google-oauth-client:1.19.0
| +--- com.google.http-client:google-http-client:1.19.0
| | +--- com.google.code.findbugs:jsr305:1.3.9
| | \--- org.apache.httpcomponents:httpclient:4.0.1
| | +--- org.apache.httpcomponents:httpcore:4.0.1
| | +--- commons-logging:commons-logging:1.1.1
| | \--- commons-codec:commons-codec:1.3
| \--- com.google.code.findbugs:jsr305:1.3.9
+--- com.google.http-client:google-http-client-jackson2:1.19.0
| +--- com.google.http-client:google-http-client:1.19.0 (*)
| \--- com.fasterxml.jackson.core:jackson-core:2.1.3
\--- com.google.guava:guava-jdk5:13.0
_debugTestApk - ## Internal use, do not manually configure ##
No dependencies
_debugTestCompile - ## Internal use, do not manually configure ##
No dependencies
_releaseApk - ## Internal use, do not manually configure ##
+--- com.android.support:multidex:1.0.0 -> 1.0.1
+--- com.android.support:multidex:1.0.+ -> 1.0.1
+--- project :sherlockNavigationDrawer
| +--- com.actionbarsherlock:actionbarsherlock:4.4.0
| \--- com.android.support:support-v13:+ -> 21.0.3
| \--- com.android.support:support-v4:21.0.3
| \--- com.android.support:support-annotations:21.0.3
+--- project :facebookSDK
| \--- com.android.support:support-v13:+ -> 21.0.3 (*)
+--- project :myLibrary
| +--- com.android.support:support-v13:+ -> 21.0.3 (*)
| +--- com.google.code.gson:gson:2.2.4
| +--- com.actionbarsherlock:actionbarsherlock:4.4.0
| \--- com.nostra13.universalimageloader:universal-image-loader:1.9.3
+--- project :viewPagerLibrary
| \--- com.android.support:support-v13:+ -> 21.0.3 (*)
+--- org.apmem.tools:layouts:1.5
+--- com.github.amlcurran.showcaseview:library:5.0.0
+--- com.jakewharton:butterknife:6.0.0
+--- com.google.android.gms:play-services:+ -> 6.5.87
| \--- com.android.support:support-v4:21.0.0 -> 21.0.3 (*)
+--- com.android.support:support-v13:21.0.0 -> 21.0.3 (*)
\--- com.google.apis:google-api-services-youtube:v3-rev120-1.19.0
\--- com.google.api-client:google-api-client:1.19.0
+--- com.google.oauth-client:google-oauth-client:1.19.0
| +--- com.google.http-client:google-http-client:1.19.0
| | +--- com.google.code.findbugs:jsr305:1.3.9
| | \--- org.apache.httpcomponents:httpclient:4.0.1
| | +--- org.apache.httpcomponents:httpcore:4.0.1
| | +--- commons-logging:commons-logging:1.1.1
| | \--- commons-codec:commons-codec:1.3
| \--- com.google.code.findbugs:jsr305:1.3.9
+--- com.google.http-client:google-http-client-jackson2:1.19.0
| +--- com.google.http-client:google-http-client:1.19.0 (*)
| \--- com.fasterxml.jackson.core:jackson-core:2.1.3
\--- com.google.guava:guava-jdk5:13.0
_releaseCompile - ## Internal use, do not manually configure ##
+--- com.android.support:multidex:1.0.0 -> 1.0.1
+--- com.android.support:multidex:1.0.+ -> 1.0.1
+--- project :sherlockNavigationDrawer
| +--- com.actionbarsherlock:actionbarsherlock:4.4.0
| \--- com.android.support:support-v13:+ -> 21.0.3
| \--- com.android.support:support-v4:21.0.3
| \--- com.android.support:support-annotations:21.0.3
+--- project :facebookSDK
| \--- com.android.support:support-v13:+ -> 21.0.3 (*)
+--- project :myLibrary
| +--- com.android.support:support-v13:+ -> 21.0.3 (*)
| +--- com.google.code.gson:gson:2.2.4
| +--- com.actionbarsherlock:actionbarsherlock:4.4.0
| \--- com.nostra13.universalimageloader:universal-image-loader:1.9.3
+--- project :viewPagerLibrary
| \--- com.android.support:support-v13:+ -> 21.0.3 (*)
+--- org.apmem.tools:layouts:1.5
+--- com.github.amlcurran.showcaseview:library:5.0.0
+--- com.jakewharton:butterknife:6.0.0
+--- com.google.android.gms:play-services:+ -> 6.5.87
| \--- com.android.support:support-v4:21.0.0 -> 21.0.3 (*)
+--- com.android.support:support-v13:21.0.0 -> 21.0.3 (*)
\--- com.google.apis:google-api-services-youtube:v3-rev120-1.19.0
\--- com.google.api-client:google-api-client:1.19.0
+--- com.google.oauth-client:google-oauth-client:1.19.0
| +--- com.google.http-client:google-http-client:1.19.0
| | +--- com.google.code.findbugs:jsr305:1.3.9
| | \--- org.apache.httpcomponents:httpclient:4.0.1
| | +--- org.apache.httpcomponents:httpcore:4.0.1
| | +--- commons-logging:commons-logging:1.1.1
| | \--- commons-codec:commons-codec:1.3
| \--- com.google.code.findbugs:jsr305:1.3.9
+--- com.google.http-client:google-http-client-jackson2:1.19.0
| +--- com.google.http-client:google-http-client:1.19.0 (*)
| \--- com.fasterxml.jackson.core:jackson-core:2.1.3
\--- com.google.guava:guava-jdk5:13.0
androidJacocoAgent - The Jacoco agent to use to get coverage data.
\--- org.jacoco:org.jacoco.agent:0.7.1.201405082137
androidJacocoAnt - The Jacoco ant tasks to use to get execute Gradle tasks.
\--- org.jacoco:org.jacoco.ant:0.7.1.201405082137
+--- org.jacoco:org.jacoco.core:0.7.1.201405082137
| \--- org.ow2.asm:asm-debug-all:5.0.1
+--- org.jacoco:org.jacoco.report:0.7.1.201405082137
| +--- org.jacoco:org.jacoco.core:0.7.1.201405082137 (*)
| \--- org.ow2.asm:asm-debug-all:5.0.1
\--- org.jacoco:org.jacoco.agent:0.7.1.201405082137
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
apk - Classpath packaged with the compiled main classes.
No dependencies
archives - Configuration for archive artifacts.
No dependencies
compile - Classpath for compiling the main sources.
+--- com.android.support:multidex:1.0.+ -> 1.0.1
+--- project :sherlockNavigationDrawer
| +--- com.actionbarsherlock:actionbarsherlock:4.4.0
| \--- com.android.support:support-v13:+ -> 21.0.3
| \--- com.android.support:support-v4:21.0.3
| \--- com.android.support:support-annotations:21.0.3
+--- project :facebookSDK
| \--- com.android.support:support-v13:+ -> 21.0.3 (*)
+--- project :myLibrary
| +--- com.android.support:support-v13:+ -> 21.0.3 (*)
| +--- com.google.code.gson:gson:2.2.4
| +--- com.actionbarsherlock:actionbarsherlock:4.4.0
| \--- com.nostra13.universalimageloader:universal-image-loader:1.9.3
+--- project :viewPagerLibrary
| \--- com.android.support:support-v13:+ -> 21.0.3 (*)
+--- org.apmem.tools:layouts:1.5
+--- com.github.amlcurran.showcaseview:library:5.0.0
+--- com.jakewharton:butterknife:6.0.0
+--- com.google.android.gms:play-services:+ -> 6.5.87
| \--- com.android.support:support-v4:21.0.0 -> 21.0.3 (*)
+--- com.android.support:support-v13:21.0.0 -> 21.0.3 (*)
\--- com.google.apis:google-api-services-youtube:v3-rev120-1.19.0
\--- com.google.api-client:google-api-client:1.19.0
+--- com.google.oauth-client:google-oauth-client:1.19.0
| +--- com.google.http-client:google-http-client:1.19.0
| | +--- com.google.code.findbugs:jsr305:1.3.9
| | \--- org.apache.httpcomponents:httpclient:4.0.1
| | +--- org.apache.httpcomponents:httpcore:4.0.1
| | +--- commons-logging:commons-logging:1.1.1
| | \--- commons-codec:commons-codec:1.3
| \--- com.google.code.findbugs:jsr305:1.3.9
+--- com.google.http-client:google-http-client-jackson2:1.19.0
| +--- com.google.http-client:google-http-client:1.19.0 (*)
| \--- com.fasterxml.jackson.core:jackson-core:2.1.3
\--- com.google.guava:guava-jdk5:13.0
然而,当我运行Android Studio“Analyze Dependencies”功能时,我仍然看到“android-support-v13.jar”出现了4次。
我正在使用Android Gradle插件版本0.14.2
我的项目结构:
2015年1月5日更新
启用multidex允许我运行该应用。但是,我不相信我的应用程序已达到65k方法限制。所以,这应该只被视为一种解决方法。
答案 0 :(得分:4)
像Scott Barta所说,这是dex文件的限制,而不是多个库的问题。
此问题已被触发,因为Google Play服务库非常庞大并且您将其包括在内:
compile 'com.google.android.gms:play-services:+'
这就是谷歌为游戏服务提供粒度管理的原因: https://developer.android.com/google/play-services/setup.html#split
您现在可以只选择要包含在项目中的所需服务,并减少您的dex文件大小。您应该能够以这种方式删除multidex。
希望它会帮助某人
答案 1 :(得分:0)
我使用Intellij 13.0.1来构建非gradle项目,所以这可能不适合你。但是,要知道我的项目使用了多少库,或者添加/删除任何我通常去的文件&gt;项目结构&gt;模块,然后查看依赖项以解决任何错误。您还可以删除重复项。