我遇到了一个非常愚蠢的问题。 我无法组装我的项目。
我创建了单个项目,例如数据库管理,api,自定义布局等。现在我正在尝试将所有这些项目合并为一个,以构建单个应用程序。
但不幸的是,它没有像我收到这个错误那样有效:
任务执行失败':app:transformDexArchiveWithDexMergerForDebug'。 com.android.build.api.transform.TransformException:com.android.dex.DexException:多个dex文件定义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}"
}
:app(根项目)
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
可能,我错过了看到明显的 我非常感谢你的帮助!
答案 0 :(得分:6)
问题解决了! 这是一个错误的公共 - 依赖性。 可以在此处找到此失败的原因:What is the difference between maven dependencies org.apache.commons:commons-io and commons-io:commons-io?
只需替换
实施'org.apache.commons:commons-io:1.3.2'
带
实施'commons-io:commons-io:1.3.2'