多个索引文件定义Landroid/support/v4/accessibilityservice/accessibilityservice-infocompat

多个索引文件定义Landroid/support/v4/accessibilityservice/accessibilityservice-infocompat,android,gradle,android-support-library,android-gradle-plugin,Android,Gradle,Android Support Library,Android Gradle Plugin,如果从命令行运行gradle assembleDebug,我会突然遇到以下错误: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dx.util.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl; at c

如果从命令行运行
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)
如果我对v4进行grep,我会在构建文件夹中看到两个文件

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文件仅包含此支持库:

compile 'com.android.support:support-v13:19.0.0'
我很难理解r7库是如何以某种方式包含进来的。我已经运行了
gradleclean
,当我重新运行assembleDebug时,它总是出现在那里

如果我在build目录中grep for r7,我会在文件中看到它:

Binary file build/exploded-bundles/ComGoogleAndroidGmsPlayServices4030.aar/classes.jar matches
如果我不包括v13,那么其他东西就不会编译

但是v13不包括v4支持库吗

这是游戏服务AAR捆绑包和v13库之间的不兼容吗

我从gradleplease.appspot.com抓取了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-jackson2:1.17.0-rc'
compile 'org.apache.commons:commons-lang3:3.2'
compile 'com.google.code.gson:gson:2.2.4'
}
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'
}
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'
}

运行
gradle-q依赖项
(或
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
然后,使用
exclude
指令阻止该依赖项。就我而言,它来自我的CWAC相机库,因此我使用:

dependencies {
    compile('com.commonsware.cwac:camera-v9:0.5.4') {
      exclude module: 'support-v4'
    }

    compile 'com.android.support:support-v4:18.0.+'
}
(其中第二个
compile
语句指示实际需要的版本)

这应该会解决问题,如果再次运行依赖关系报告,您将看到:

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

我也有同样的错误,但这是因为我最近从使用v4改为使用v13。所以我所要做的就是清理这个项目。

还要注意的是,你可以通过进入你的android Studio Gradle视图,选择目标“androidDependencies”来查看你的android依赖项


还有一个提示:我遇到了这个问题,直到我从项目和相关模块/库项目的libs文件夹中删除了v4支持库

我解决了类似的错误,在android块内的build.gradle文件中添加了以下代码

android {
    dexOptions {
        preDexLibraries = false
    }
}

在Android Studio中,转到build.gradle(检查项目和模块build.gradle文件)并搜索重复的依赖项


删除您的项目不需要的内容。

如果有人发现来自的答案无法应用于android library项目,下面是要修复的代码片段

编译(project(':yourandoidlibrary')){ 排除模块:“support-v13” }

你会发现问题的

找到不支持的Gradle DSL方法:“exclude()”

如果你使用 编译项目(':yourandoidlibrary'){ 排除模块:“support-v13” }

区别在于项目之前的手镯(“

1. The select project 
2. Go to File -> **Project Structure**
3. Select app in **module** section on left hand panel
4. Select **Dependency** tab
5. Your able to see jars you have added in eclipse project for v4 and v13.
6. Remove that jar by clicking on minus sign at bottom after selection
7. Click on Plus sign select **Library Dependency** 
8. Choose V4 and V13 if added
9. Press Ok and Clean and Rebuild your project
对于我来说,使用项目依赖关系不起作用,我唯一能让它起作用的方法是通过以下语法:

configurations {
    dependencies {
        compile(project(':Android-SDK')) {
            compile.exclude module: 'support-v4'
        }
    }
}

其中:Android SDK是您的项目名称。

我在一个遗留项目上遇到了相同的错误。我的错误是支持库包含了两次:一次在google play services库中,另一次作为独立库

我就是这样修复的:

错误的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-jackson2:1.17.0-rc'
compile 'org.apache.commons:commons-lang3:3.2'
compile 'com.google.code.gson:gson:2.2.4'
}
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'
}
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'
}
好身材。格雷德尔:

 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-jackson2:1.17.0-rc'
compile 'org.apache.commons:commons-lang3:3.2'
compile 'com.google.code.gson:gson:2.2.4'
}
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'
}
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'
}
希望对某人有所帮助:-)

我删除了 编译'com.android.support:support-v4:18.0.+'
在dependencies中,如果您已从Eclipse导入了项目,它将起作用

1. The select project 
2. Go to File -> **Project Structure**
3. Select app in **module** section on left hand panel
4. Select **Dependency** tab
5. Your able to see jars you have added in eclipse project for v4 and v13.
6. Remove that jar by clicking on minus sign at bottom after selection
7. Click on Plus sign select **Library Dependency** 
8. Choose V4 and V13 if added
9. Press Ok and Clean and Rebuild your project
我在将Eclipse项目导入Android studio后遇到的情况


希望这有帮助

我也遇到了同样的问题,而且由于库的原因,我的应用程序似乎有太多的方法:

解决方法是:

android {
   defaultConfig {
   ...
   multiDexEnabled = true
   }
}

更多信息

我正在使用
com.google.android.gms:play services analytics:8.3.0
android-support-v13.jar
无法使
排除模块:“support-v4”
正常工作

对我有效的是使用
android-support-v13
artifact,而不是
android-support-v13.jar
文件

即代替

dependencies {
compile ('com.google.android.gms:play-services-analytics:8.3.0')
compile files('libs/android-support-v13.jar')
}

我曾经

dependencies {
compile ('com.google.android.gms:play-services-analytics:8.3.0')
compile ('com.google.android:android-support-v13')

}因为一幅画抵得上千言万语

让像我这样的初学者更容易更快地完成这项任务。这是屏幕截图,显示了@edsappfactory.com发布的对我有用的答案:

首先打开Androidstudio右侧的Gradle视图,在应用程序的项目中进入任务然后进入Android然后右键单击androidDependencies,然后选择运行:

第二步您将看到如下内容:

我发布这篇文章的主要原因是不容易知道在哪里执行
gradle
任务或上面发布的命令。所以这也是他们被驱逐的地方

因此,要执行gradle命令:

第一:

第二:

虽然很容易

就这样


谢谢。

从Gradle缓存中删除所有文件修复了我的问题。

在Linux上:

rm -rf ~/.gradle/caches/*

这是一个恼人的问题,可能需要一些时间才能找到根本原因。您应该继续的方式是@commonware answer

我最近面对这个问题,发现很难解决

我的问题是我在build.gradle中包含了一个“+”版本的库。最新版本的库包含一个旧的dex和bang。

我恢复到旧版本的库并解决了它

运行您的androidDependencies并查看真正发生的事情是很好的。在构建文件夹中搜索也很好

最重要的是,Android Studio 2.2提供内置功能来跟踪此问题


快乐编码人

在我的例子中,问题是由版本不一致引起的:

Build tools 25
compileSdk 24
targetSdk 24
Support library 24

解决方案很简单:使一切都成为25版

我在升级时开始出现这个错误
./gradlew app:dependencies
+--- project :react-native-palette
|    +--- com.facebook.react:react-native:0.20.+ -> 0.44.2
|    |    +--- javax.inject:javax.inject:1
|    |    +--- com.android.support:appcompat-v7:23.0.1
|    |    |    \--- com.android.support:support-v4:23.0.1
|    |    |         \--- com.android.support:support-annotations:23.0.1 -> 24.2.1
...
|    \--- com.android.support:palette-v7:24.+ -> 24.2.1
|         +--- com.android.support:support-compat:24.2.1
|         |    \--- com.android.support:support-annotations:24.2.1
|         \--- com.android.support:support-core-utils:24.2.1
|              \--- com.android.support:support-compat:24.2.1 (*)
+--- com.android.support:appcompat-v7:23.0.1 (*)
\--- com.facebook.react:react-native:+ -> 0.44.2 (*)
dependencies {
    compile project(':react-native-palette')
    compile project(':react-native-image-picker')
    compile project(':react-native-camera')
    compile fileTree(dir: "libs", include: ["*.jar"])
    // compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.android.support:appcompat-v7:24.2.1"
    compile "com.facebook.react:react-native:+"
}
cordova.system.library.7=com.android.support:appcompat-v7:27.1.0
configurations {
        all*.exclude group: 'com.android.support', module: 'support-compat'
        all*.exclude group: 'com.android.support', module: 'support-core-ui'
    }