多个dex文件定义Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20989317/
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
Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat
提问by xrd
If I run gradle assembleDebug
from the command line, I am suddenly getting this error:
如果我从命令行运行gradle assembleDebug
,我会突然收到此错误:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.util.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:592)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:550)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:531)
at com.android.dx.merge.DexMerger.mergeDexBuffers(DexMerger.java:168)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:186)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:300)
at com.android.dx.command.dexer.Main.run(Main.java:232)
at com.android.dx.command.dexer.Main.main(Main.java:174)
at com.android.dx.command.Main.main(Main.java:91)
If I grep for v4 I see two files inside my build folder.
如果我 grep for v4,我会在构建文件夹中看到两个文件。
Binary file build/pre-dexed/debug/support-v4-19.0.0-2ba5fdd60a6c3836b3104a863fe42897da1fa9d1.jar matches
Binary file build/pre-dexed/debug/support-v4-r7-227d905d79b23b20866531d4f700446c040a2ccb.jar matches
My gradle file includes only this support library:
我的 gradle 文件只包含这个支持库:
compile 'com.android.support:support-v13:19.0.0'
I am stumped as to how the r7 library is included somehow. I've run gradle clean
and it always appears there when I rerun assembleDebug.
我对如何以某种方式包含 r7 库感到困惑。我已经运行了gradle clean
,当我重新运行 assembleDebug 时它总是出现在那里。
If I grep for r7 inside the build directory, I see it inside the file:
如果我在 build 目录中 grep for r7 ,我会在文件中看到它:
Binary file build/exploded-bundles/ComGoogleAndroidGmsPlayServices4030.aar/classes.jar matches
If I don't include v13, then other things don't compile.
如果我不包含 v13,则其他内容无法编译。
But doesn't v13 include v4 support library?
但是 v13 不包括 v4 支持库吗?
Is this an incompatibility between play services AAR bundle and the v13 library?
这是播放服务 AAR 包和 v13 库之间的不兼容吗?
I grabbed the gradle file from gradleplease.appspot.com.
我从 gradleplease.appspot.com 获取了 gradle 文件。
Removing play services does not fix it; same error.
删除播放服务并不能解决问题;同样的错误。
My dependencies inside build.gradle:
我在 build.gradle 中的依赖项:
dependencies {
// Google Play Services
//compile 'com.google.android.gms:play-services:4.0.30'
// Support Libraries
//compile 'com.android.support:support-v4:19.0.0'
///compile 'com.android.support:appcompat-v7:19.0.0'
//compile 'com.android.support:gridlayout-v7:19.0.0'
compile 'com.android.support:support-v13:19.0.0'
compile 'org.eclipse.mylyn.github:org.eclipse.egit.github.core:2.1.5'
compile 'commons-codec:commons-codec:1.9'
compile 'com.madgag:markdownj-core:0.4.1'
compile 'com.wu-man:android-oauth-client:0.0.2'
compile 'com.google.http-client:google-http-client-Hymanson2:1.17.0-rc'
compile 'org.apache.commons:commons-lang3:3.2'
compile 'com.google.code.gson:gson:2.2.4'
}
回答by CommonsWare
Run gradle -q dependencies
(or gradle -q :projectName:dependencies
) to generate a dependency report. You should see where r7
is coming from, such as:
运行gradle -q dependencies
(或gradle -q :projectName:dependencies
)以生成依赖关系报告。您应该看到r7
来自哪里,例如:
compile - Classpath for compiling the main sources.
+--- com.commonsware.cwac:camera-v9:0.5.4
| +--- com.actionbarsherlock:actionbarsherlock:4.4.0
| | \--- com.google.android:support-v4:r7
| +--- com.commonsware.cwac:camera:0.5.4
| \--- com.android.support:support-v4:18.0.+ -> 18.0.0
\--- com.android.support:support-v4:18.0.+ -> 18.0.0
Then, use the exclude
directive to block that dependency. In my case, it is coming from my CWAC-Camera library, and so I use:
然后,使用该exclude
指令来阻止该依赖项。就我而言,它来自我的 CWAC-Camera 库,所以我使用:
dependencies {
compile('com.commonsware.cwac:camera-v9:0.5.4') {
exclude module: 'support-v4'
}
compile 'com.android.support:support-v4:18.0.+'
}
(where the second compile
statement indicates what version you actually want)
(其中第二个compile
语句表示您实际想要的版本)
That should clear matters up, as you will see if you run the dependency report again:
这应该会解决问题,因为您将看到是否再次运行依赖关系报告:
compile - Classpath for compiling the main sources.
+--- com.commonsware.cwac:camera-v9:0.5.4
| +--- com.actionbarsherlock:actionbarsherlock:4.4.0
| \--- com.commonsware.cwac:camera:0.5.4
\--- com.android.support:support-v4:18.0.+ -> 18.0.0
回答by mike.tihonchik
I solved similar error by adding following piece of code to my build.gradlefile inside the android block.
我通过将以下代码添加到android 块内的build.gradle文件解决了类似的错误。
android {
dexOptions {
preDexLibraries = false
}
}
回答by MBH
Since A picture is worth a thousand words
既然一张图值一千字
To make it easier and faster to get this task done with beginners like me. this is the screenshots that shows the answer posted by @edsappfactory.comthat worked for me:
为了让像我这样的初学者更容易、更快地完成这项任务。这是显示@edsappfactory.com发布的对我有用的答案的屏幕截图:
Firstopen the Gradle view on the right side of Androidstudio, in your app's item go to Tasks
then Android
then right-click androidDependencies
then choose Run
:
首先打开Androidstudio右侧的摇篮视图,在您的应用程序的项目进入Tasks
,然后Android
再单击鼠标右键androidDependencies
,然后选择Run
:
Secondyou will see something like this :
其次你会看到这样的东西:
The main reason i posted this that it was not easy to know where to execute a gradle
task or the commands posted above. So this is where to excute them as well.
我发布这个的主要原因是不容易知道在哪里执行gradle
任务或上面发布的命令。所以这也是执行它们的地方。
SO, to execute gradle command:
所以,要执行 gradle 命令:
First:
第一的:
Second:
第二:
Easy as it is.
就这么简单。
Thats it.
就是这样。
Thank you.
谢谢你。
回答by Ed Manners
Also to note you can see your android dependencies, by going to your Android Studio Gradle view, and selecting the target "androidDependencies".
另请注意,您可以通过转到 Android Studio Gradle 视图并选择目标“androidDependencies”来查看您的 android 依赖项。
One more tip: I was having this issue, until I removed the v4 support lib from the libs folder in both the project and my related module/library project(s).
还有一个提示:我遇到了这个问题,直到我从项目和相关模块/库项目的 libs 文件夹中删除了 v4 支持库。
回答by user3562927
I started getting this error when upgrading to ButterKnife 8.5.1. None of the other answers here worked for me.
升级到 ButterKnife 8.5.1 时,我开始收到此错误。这里的其他答案都不适合我。
I used gradle -q :app:dependencies
to see the tree, and then looked through jar files until I found the conflict. The conflict was that butterknife's dependency on com.android.support:support-compat:25.1.0
contains a version of the accessibility class, and com.android.support:support-v4:23.1.1
also contains the class.
以前gradle -q :app:dependencies
是看树,然后翻看jar文件,直到发现冲突。冲突在于,butterknife 的依赖com.android.support:support-compat:25.1.0
包含一个可访问性类的版本,并且com.android.support:support-v4:23.1.1
还包含该类。
I solved it by changing my dependency from this:
我通过改变我的依赖来解决它:
compile 'com.jakewharton:butterknife:8.5.1'
to this:
对此:
compile('com.jakewharton:butterknife:8.5.1') {
exclude module: 'support-compat'
}
It doesn't seem to affect ButterKnife's operation so far.
到目前为止,它似乎没有影响 ButterKnife 的操作。
Edit: There is a better solution, which was to upgrade my android support libraries to match ButterKnife's:
编辑:有一个更好的解决方案,即升级我的 android 支持库以匹配 ButterKnife 的:
compile('com.android.support:appcompat-v7:25.2.0')
compile('com.android.support:design:25.2.0')
compile 'com.jakewharton:butterknife:8.5.1'
回答by Tony Thompson
In case anyone finds out that the answer from CommonsWarecould not be applied to android library project, here is the snippet to fix
如果有人发现CommonsWare的答案无法应用于 android 库项目,这里是要修复的片段
compile (project(':yourAndroidLibrary')){ exclude module: 'support-v13' }
编译(项目(':你的AndroidLibrary')){排除模块:'support-v13'}
You will find problems
你会发现问题
Unsupported Gradle DSL method found: 'exclude()'
发现不受支持的 Gradle DSL 方法:'exclude()'
if you use compile project(':yourAndroidLibrary'){ exclude module: 'support-v13' }
如果你使用 compile project(':yourAndroidLibrary'){ exclude module: 'support-v13' }
The differences are the bracelet "("and ")"before "project".
区别在于“project”之前的手镯“(”和“) ”。
回答by Pellet
exclude module: 'support-v4'
Would not work for me with a project dependency, the only way I could get it to work was via the following syntax:
对于项目依赖项对我不起作用,我可以让它工作的唯一方法是通过以下语法:
configurations {
dependencies {
compile(project(':Android-SDK')) {
compile.exclude module: 'support-v4'
}
}
}
Where :Android-SDK is your project name.
其中:Android-SDK 是您的项目名称。
回答by Giannis P
I had the same problem and it seems that my app had too many methods because of the libraries: http://developer.android.com/tools/building/multidex.html
我遇到了同样的问题,由于库的原因,我的应用程序似乎有太多方法:http: //developer.android.com/tools/building/multidex.html
Solved it with:
解决了它:
android {
defaultConfig {
...
multiDexEnabled = true
}
}
More here Error:Execution failed for task ':app:dexDebug'. > comcommand finished with non-zero exit value 2
回答by ashishduh
I had this same error but it was because I had recently changed from using v4 to v13. So all I had to do was clean the project.
我有同样的错误,但这是因为我最近从使用 v4 更改为 v13。所以我所要做的就是清理项目。
回答by voghDev
I had the same error on a legacy project. My fault was that the support-library was included twice: Once inside google-play-services lib, and another as standalone.
我在遗留项目上遇到了同样的错误。我的错是 support-library 被包含了两次:一次在 google-play-services lib 中,另一个作为独立的。
This is how I fixed it:
这是我修复它的方式:
BAD build.gradle:
糟糕的 build.gradle:
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/core-2.2.jar')
compile files('libs/universal-image-loader-1.8.5-with-sources.jar')
compile 'com.google.android.gms:play-services:3.2.65'
}
GOOD build.gradle:
好的 build.gradle:
dependencies {
// compile files('libs/android-support-v4.jar') // not needed
compile files('libs/core-2.2.jar')
compile files('libs/universal-image-loader-1.8.5-with-sources.jar')
compile 'com.google.android.gms:play-services:3.2.65'
}
Hope it helps someone :-)
希望它可以帮助某人:-)