Android Studio Gradle 错误:多个 dex 文件定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22851103/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Studio Gradle Error: Multiple dex files define
提问by My House
I'm getting this error when trying to build my project in Android Studio (I'm trying to migrate from Eclipse):
Output:
尝试在 Android Studio 中构建我的项目时出现此错误(我正在尝试从 Eclipse 迁移):
输出:
UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl; at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
after googling and checking stackoverflow the most likely cause is duplicate library references.
I have a number of libraries in my project such as Facebook SDK, SlidingMenu, etc. that required android-support-v4.jar, so I copied that into my main project's /libs folder and subsequently removed it from all the other projects libs folder. Then I went to "Open Module Settings" and added the support-v4 as a library dependency for the libraries that needed it (e.g. Facebook SDK).
Then clean project -> run but I'm still getting this multiple dex files error
在谷歌搜索并检查 stackoverflow 后,最可能的原因是重复的库引用。
我的项目中有许多库(例如 Facebook SDK、SlidingMenu 等)需要 android-support-v4.jar,因此我将其复制到主项目的 /libs 文件夹中,然后将其从所有其他项目的 libs 文件夹中删除. 然后我转到“打开模块设置”并将 support-v4 添加为需要它的库(例如 Facebook SDK)的库依赖项。
然后清理项目-> 运行,但我仍然收到此多个 dex 文件错误
running gradle -q dependencies
shows:
跑步gradle -q dependencies
节目:
+--- project :facebook-android-sdk-3.5.1:facebook
| \--- com.android.support:support-v4:+ -> 19.1.0
+--- project :SlidingMenu:library
| \--- com.android.support:support-v4:+ -> 19.1.0
Is that okay? If I remove this library dependency in the Module Settings then I will get even more errors while trying to compile my project
可以吗?如果我在模块设置中删除此库依赖项,那么在尝试编译我的项目时会出现更多错误
回答by Aaron Dancygier
In your build.gradle file try adding the following block inside your android block.
在您的 build.gradle 文件中,尝试在您的 android 块中添加以下块。
dexOptions {
preDexLibraries = false
}
回答by Shubham Kushwah
Just a Clean Build worked for me , Just do this in Android Studio:
只是一个 Clean Build 对我有用,只需在 Android Studio 中执行此操作:
Got to Build > Clean Project
必须构建 > 清理项目
回答by Devix
dexOptions {
preDexLibraries = false
}
and
和
Got to Build > Clean Project
and
和
Got to Build > Rebuild Project
回答by jiong103
The correct answer is:
正确答案是:
dexOptions {
preDexLibraries = false
}