多个dex文件在android studio中定义了Landroid/support/v4/
- 作者: 大姨妈走了_
- 来源: 51数据库
- 2022-11-02
问题描述
我可以与许多库集成(添加和工作).
但是对于 ActionBarSherlock 库,我有很多问题.
But as for ActionBarSherlock library, I have so many problems with it.
First Issue是热门issue多个dex文件定义,
我知道 duplicated android-support-v4.jar 导致它,但我现在无法解决这个问题:
I know The duplicated android-support-v4.jar causes it, but I can not solve this issue now :
Error:Execution failed for task ':fitness:dexDebug'.
Error Code:
2
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)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
我遵循了 同样的错误中的答案.它使用了:
I followed the answer in same error. It used :
dependencies {
compile('...') {
exclude module: 'support-v4'
}
compile 'com.android.support:support-v4:18.0.+'
}
但我收到了第二个问题:unsupported Gradle DSL method found: 'exclude()'! 错误.因此,我像这样更改了 main module 的 build.gradle:
But I received Second Issue : unsupported Gradle DSL method found: 'exclude()'! error. Therefore I changed build.gradle of main module like this:
//configurations {
// all*.exclude group: 'com.android.support', module: 'support-v4'
//}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':google-play-services')
compile files('/google-play-services/libs/google-play-services.jar')
compile (project(':actionbarsherlock')) {
exclude(module: 'support-v4')
}
compile 'com.android.support:support-v4:18.0.+'
}
已解决 Second Issue,但还是得到First Issue Multiple dex files define错误.
Solved Second Issue, But still get First Issue Multiple dex files define error.
我阅读了很多主题,但现在无法解决First Issue,
I read many topics, but can not solve First Issue now,
请帮帮我,
谢谢,
p/s : 我可以与 Gradle 成功同步,但运行时出现上述错误.
我使用的是 Android Studio 0.5.5
编辑
build.gradle,它只有一个android-support-v4.jar:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
setting.gradle 像这样:
include ':fitness', ':google-play-services',':actionbarsherlock'
@Garbriele:我更新了新问题,显示 build.gradle of project 和 build.gradle of main moduleproject的build.gradle:
@Garbriele : I updated new question, show build.gradle of project and build.gradle of main module build.gradle of project:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
主模块的build.gradle编辑后:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar' // Get following error in this line
}
我在下面收到此错误:
好的,感谢@Garbriele 的评论,我已经用这个解决了这个问题:
Okay, thanks for @Garbriele comment, I already fixed this by using this :
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar' // Get following error in this line
}
EDIT 2当我这样说时:
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.google.android.gms:play-services:+'
}
仍然得到First Issue Multiple dex files define错误.
我现在想要的是如何通过Maven成功添加com.google.android.gms:play-services库,
What I want now is how to add com.google.android.gms:play-services library via Maven successfully,
请帮帮我,
谢谢,
更新
按照以下步骤操作后:
通过 Maven 将库放在主模块的 build.gradle 中:compile 'com.google.android.gms:play-services:+'
重启Android Studio
使用 gradle 同步项目
不再出现此错误.
推荐答案
好奇怪,
当我像这样设置我的依赖项时:
When I setup my dependencies like this :
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.google.android.gms:play-services:+'
}
我仍然收到 First Issue Multiple dex files define 错误.
I still get the First Issue Multiple dex files define error.
但是在执行了这些步骤之后:
But after following these steps:
通过 Gradle 将库放到主模块的 build.gradle 中:compile 'com.google.android.gms:play-services:+'
重启Android Studio
使用 gradle 同步项目
我不再收到此错误.
