假设我的Android Studio项目中有2个模块:
---- :A
---- :B
其中:A依赖于B:
---- :A ---> + :B
---- :B
A和B都需要库L:
使事情复杂化---- :A ---> + :B
+ :L
---- :B ---> + :L
最初包含的模块的gradle文件:
模块A:
dependencies {
compile project(':B')
compile 'com.L:library:1.0.0'
}
模块B:
dependencies {
compile 'com.L:library:1.0.0'
}
但这会给出一个错误,表明在dex文件的inputList.txt中提供了多个库:
Execution failed for task ':funtainment:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Development\Android\AndroidStudio\Sdk\build-tools\21.1.2\dx.bat --dex --no-optimize --output C:\Development\Workspace\Android\AndroidStudio\Funtainment\funtainment\build\intermediates\dex\debug --input-list=C:\Development\Workspace\Android\AndroidStudio\Funtainment\funtainment\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/nineoldandroids/animation/Animator$AnimatorListener;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
所以我尝试了一个不同的结构,它在Eclipse上适用于类似的情况:只需从模块A中删除库依赖项:
---- :A ---> + :B
---- :B ---> + :L
模块的gradle文件包含:
模块A:
dependencies {
compile project(':B')
}
模块B:
dependencies {
compile 'com.L:library:1.0.0'
}
但是我得到了和以前一样的错误!
其他相关信息:
:A:dexDebug
)这是Android和Android Studio的错误还是这种预期的行为? 如何允许这两个模块引用此库而不会导致将多个库添加到dex中并导致错误?
答案 0 :(得分:1)
您可以使用exclude
compile ('great:library:1.0') {
exclude module: 'lib'
}
或
compile (project(':mymodule')) {
exclude module: 'lib'
}