我遇到了一個非常愚蠢的問題。 我無法組裝我的項目。多個dex文件定義了Lorg/apache/commons/io/IOUtils;
我創建了單個項目,例如,數據庫管理,api,自定義佈局等。現在我正在嘗試將所有這些項目合併爲一個,以構建一個應用程序。
但unfortunaley它excpected,因爲我得到這個錯誤不工作:
Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'. com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lorg/apache/commons/io/IOUtils;
我的依賴關係樹如下:
6.0.2 (*)
| | +--- com.android.support:support-core-utils:26.0.2
| | | +--- com.android.support:support-annotations:26.0.2
| | | \--- com.android.support:support-compat:26.0.2 (*)
| | +--- com.android.support:support-core-ui:26.0.2
| | | +--- com.android.support:support-annotations:26.0.2
| | | \--- com.android.support:support-compat:26.0.2 (*)
| | \--- com.android.support:support-fragment:26.0.2
| | +--- com.android.support:support-compat:26.0.2 (*)
| | +--- com.android.support:support-core-ui:26.0.2 (*)
| | \--- com.android.support:support-core-utils:26.0.2 (*)
| +--- com.android.support:support-vector-drawable:26.0.2
| | +--- com.android.support:support-annotations:26.0.2
| | \--- com.android.support:support-compat:26.0.2 (*)
| \--- com.android.support:animated-vector-drawable:26.0.2
| +--- com.android.support:support-vector-drawable:26.0.2 (*)
| \--- com.android.support:support-core-ui:26.0.2 (*)
+--- com.android.support:multidex:1.0.2
+--- com.github.jetradarmobile:multibackstack:1.2.1
| \--- com.android.support:appcompat-v7:25.3.1 -> 26.0.2 (*)
+--- com.ashokvarma.android:bottom-navigation-bar:2.0.2
| +--- com.android.support:appcompat-v7:25.3.1 -> 26.0.2 (*)
| \--- com.android.support:design:25.3.1
| +--- com.android.support:support-v4:25.3.1 -> 26.0.2 (*)
| +--- com.android.support:appcompat-v7:25.3.1 -> 26.0.2 (*)
| +--- com.android.support:recyclerview-v7:25.3.1
| | +--- com.android.support:support-annotations:25.3.1 -> 26.0.2
| | +--- com.android.support:support-compat:25.3.1 -> 26.0.2 (*)
| | \--- com.android.support:support-core-ui:25.3.1 -> 26.0.2 (*)
| \--- com.android.support:transition:25.3.1
| +--- com.android.support:support-annotations:25.3.1 -> 26.0.2
| \--- com.android.support:support-v4:25.3.1 -> 26.0.2 (*)
+--- com.github.bumptech.glide:glide:4.0.0
| +--- com.github.bumptech.glide:gifdecoder:4.0.0
| | \--- com.android.support:support-annotations:25.3.1 -> 26.0.2
| +--- com.github.bumptech.glide:disklrucache:4.0.0
| \--- com.github.bumptech.glide:annotations:4.0.0
+--- com.android.support.constraint:constraint-layout:1.1.0-beta1
| \--- com.android.support.constraint:constraint-layout-solver:1.1.0-beta1
+--- com.wdullaer:swipeactionadapter:2.0.0
| \--- com.android.support:support-annotations:23.1.0 -> 26.0.2
+--- project :onboarder
| +--- com.android.support.constraint:constraint-layout:1.0.2 -> 1.1.0-beta1 (*)
| +--- com.android.support:appcompat-v7:26.0.2 (*)
| +--- com.android.support:cardview-v7:26.0.2
| | \--- com.android.support:support-annotations:26.0.2
| \--- com.android.support:support-v4:26.0.2 (*)
+--- project :DatabaseManagement
| +--- io.realm:realm-android-library:3.7.2
| | +--- com.google.code.findbugs:jsr305:3.0.2
| | +--- com.getkeepsafe.relinker:relinker:1.2.2
| | \--- io.realm:realm-annotations:3.7.2
| \--- io.realm:realm-annotations:3.7.2
\--- project :api
+--- com.google.code.gson:gson:2.8.1
+--- com.google.apis:google-api-services-youtube:v3-rev44-1.14.1-beta
| \--- com.google.api-client:google-api-client:1.14.1-beta
| \--- com.google.oauth-client:google-oauth-client:1.14.1-beta
| +--- com.google.http-client:google-http-client:1.14.1-beta
| | +--- com.google.code.findbugs:jsr305:1.3.9 -> 3.0.2
| | +--- 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
| | \--- xpp3:xpp3:1.1.4c
| \--- com.google.code.findbugs:jsr305:1.3.9 -> 3.0.2
+--- io.reactivex.rxjava2:rxandroid:2.0.1
| \--- io.reactivex.rxjava2:rxjava:2.0.1 -> 2.1.3
| \--- org.reactivestreams:reactive-streams:1.0.1
+--- io.reactivex.rxjava2:rxjava:2.1.3 (*)
\--- org.apache.commons:commons-io:1.3.2
\--- commons-io:commons-io:1.3.2
下面是我在我的項目得到了模塊:
:TOPLEVEL
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta5'
classpath "io.realm:realm-gradle-plugin:3.7.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url 'https://maven.google.com' }
maven { url 'https://oss.jfrog.org/libs-snapshot' }
}
project.ext {
minSdk=14
targetSdk=26
buildVersion="26.0.1"
compileSdk=26
supportLibraryVersion="26.0.2"
set('supportLibraryVersion',supportLibraryVersion)
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
:API
dependencies {
implementation 'org.jsoup:jsoup:1.10.3'
implementation ('com.google.http-client:google-http-client-jackson2:1.22.0')
api 'com.google.code.gson:gson:2.8.1'
api ('com.google.apis:google-api-services-youtube:v3-rev44-1.14.1-beta')
api 'io.reactivex.rxjava2:rxandroid:2.0.1'
api 'io.reactivex.rxjava2:rxjava:2.1.3'
}
:DatabaseManagment
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "com.android.support:appcompat-v7:${supportLibraryVersion}"
implementation project(':api')
implementation 'org.apache.commons:commons-io:1.3.2'
}
:onboarder
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile "com.android.support:appcompat-v7:${supportLibraryVersion}"
compile "com.android.support:cardview-v7:${supportLibraryVersion}"
compile "com.android.support:support-v4:${supportLibraryVersion}"
}
:應用程序(根項目)
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
/** Android/Google Support Libraries **/
implementation "com.android.support:appcompat-v7:${supportLibraryVersion}"
implementation 'com.android.support:multidex:1.0.2'
/** UI dependencies **/
implementation 'com.github.jetradarmobile:multibackstack:1.2.1'
//has dependencies on old appcompat version
implementation 'com.ashokvarma.android:bottom-navigation-bar:2.0.2'
//has dependencies on old appcompat version
implementation 'com.github.bumptech.glide:glide:4.0.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta1'
implementation 'com.wdullaer:swipeactionadapter:2.0.0'
implementation project(':onboarder')
/** Techniqual implementations */
implementation project(':DatabaseManagement')
implementation project(':api')
}
試圖解決方案:
近3小時,我瘋了找到一個解決方案,但沒有我已經找到工作。我無法從依賴關係樹中看到引用commons-io的雙引用正在發生,這些引用正在導致此錯誤。
Multidex不是這裏的問題,沒有multidex它也無法組裝。
我正在使用Android Studio 3 Beta 5
顯而易見,我錯過了。
我真的很感激你的幫助!
破除一切'文件樹()'行。如果實際上在'libs /'中使用裸JAR,那麼您的問題就有可能出現在其中一個問題上,因爲Gradle無法將它們與傳遞依賴關係與工件之間的依賴關係進行協調。 – CommonsWare
謝謝你指出了!我刪除了它們。不幸的是,它並沒有解決問題,因爲我的模塊沒有在libs中使用任何* .jars。但它是很好的去除不必要的代碼:) –