gpt4 book ai didi

java - 意外的顶级异常 - 多个库项目

转载 作者:搜寻专家 更新时间:2023-11-01 07:55:55 27 4
gpt4 key购买 nike

我的理解是一些库被包含了不止一次。问题是哪一种以及如何避免这种情况?

不止一次包含的可疑库:
Android 支持库。

我尝试过的:
使用以下方法之一在主模块的 Gradle 构建脚本中排除它:
方法 #1:使用“配置” block :

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

我的项目结构:
enter image description here enter image description here enter image description here

2015 年 1 月 5 日更新
启用 multidex允许我运行该应用程序。但是,我认为我的应用程序尚未达到 65k 方法的限制。因此,这只能被视为一种解决方法。

最佳答案

正如 Scott Barta 所说,这是 dex 文件的限制,而不是多个库的问题。触发此问题是因为 Google Play 服务库变得非常庞大并且您将其包括在内:编译 'com.google.android.gms:play-services:+'

这就是为什么谷歌提供播放服务的粒度管理: https://developer.android.com/google/play-services/setup.html#split

您现在可以只选择需要的服务以包含在您的项目中并减少您的 dex 文件大小。您应该能够通过这种方式删除 multidex。

希望对大家有帮助

关于java - 意外的顶级异常 - 多个库项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27739439/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com