【发布时间】:2015-05-07 23:57:05
【问题描述】:
假设我的 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'
}
但是我得到了和以前一样的错误!
其他相关信息:
- 在整个过程中没有出现任何 java 编译错误(如预期)
- 该错误仅在尝试部署时出现(特别是在
:A:dexDebug) - 上面的库“L”代表“com.nineoldandroids:library:2.4.0”
这是和 Android Studio 的错误还是这是预期的行为? 如何让这两个模块都引用这个库,而不会导致多个库被添加到 dex 中并导致错误?
【问题讨论】:
-
我昨天遇到了同样的错误,我在我的项目中包含了一个 api。您必须检查您的
yourproject/apps/libs文件夹,可能有多个同名文件。假设您在 libs 文件夹中有source和binary文件,然后从中删除源文件并尝试再次同步您的项目 -
我已确保我的项目中没有重复的 lib 文件。搜索任何此类 lib 文件仅在 intermediates 文件夹中显示重复项(由 Android Studio 在编译/部署操作期间生成,我认为这是预期的行为。因此该解决方案似乎不适用于我
标签: android module android-studio dependencies