简体   繁体   English

Android Studio Gradle 错误:多个 dex 文件定义

[英]Android Studio Gradle Error: Multiple dex files define

I'm getting this error when trying to build my project in Android Studio (I'm trying to migrate from Eclipse):尝试在 Android Studio 中构建我的项目时出现此错误(我正在尝试从 Eclipse 迁移):
Output:输出:

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.在谷歌搜索并检查 stackoverflow 后,最可能的原因是重复的库引用。
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.我的项目中有许多库(例如 Facebook SDK、SlidingMenu 等)需要 android-support-v4.jar,因此我将其复制到主项目的 /libs 文件夹中,然后将其从所有其他项目的 libs 文件夹中删除. Then I went to "Open Module Settings" and added the support-v4 as a library dependency for the libraries that needed it (eg Facebook SDK).然后我转到“打开模块设置”并将 support-v4 添加为需要它的库(例如 Facebook SDK)的库依赖项。
Then clean project -> run but I'm still getting this multiple dex files error然后清理项目-> 运行,但我仍然收到此多个 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如果我在模块设置中删除此库依赖项,那么在尝试编译我的项目时会出现更多错误

In your build.gradle file try adding the following block inside your android block.在您的 build.gradle 文件中,尝试在您的 android 块中添加以下块。

dexOptions {
    preDexLibraries = false
}

Just a Clean Build worked for me , Just do this in Android Studio:只是一个 Clean Build 对我有用,只需在 Android Studio 中执行此操作:

Got to Build > Clean Project必须构建 > 清理项目

See image for reference请参阅图像以供参考

dexOptions {
    preDexLibraries = false
}

and

Got to Build > Clean Project

and

Got to Build > Rebuild Project

The correct answer is:正确答案是:

dexOptions {
    preDexLibraries = false
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM