Multiple dex files define解决记录

引用多个library时经常会遇到Multiple dex files define错误

1
2
3
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Landroid/arch
/core/util/Function;

此时可用以下gradle命令来查看工程的引用树,找出冲突的引用库后exclude之

1
2
cd app
..\gradlew -q dependencies

最常见的是support库多次定义,经检查本文是由于引入RxLifecycle导致android.arch.lifecycle.runtime库重复引用问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
compile 'io.reactivex.rxjava2:rxjava:2.2.0'

compile('com.github.tbruyelle:rxpermissions:0.10.2', {
exclude group: 'io.reactivex.rxjava2', module: 'rxjava'
})

compile('com.trello.rxlifecycle2:rxlifecycle:2.2.2', {
exclude group: 'io.reactivex.rxjava2', module: 'rxjava'
exclude group: 'android.arch.lifecycle', module: 'runtime'
})
compile('com.trello.rxlifecycle2:rxlifecycle-android-lifecycle:2.2.2', {
exclude group: 'io.reactivex.rxjava2', module: 'rxjava'
exclude group: 'android.arch.lifecycle', module: 'runtime'
})
compile('com.trello.rxlifecycle2:rxlifecycle-android:2.2.2', {
exclude group: 'io.reactivex.rxjava2', module: 'rxjava'
exclude group: 'android.arch.lifecycle', module: 'runtime'
})
compile('com.trello.rxlifecycle2:rxlifecycle-components:2.2.2', {
exclude group: 'io.reactivex.rxjava2', module: 'rxjava'
exclude group: 'android.arch.lifecycle', module: 'runtime'
})

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :