多DEX文件定义<我的包> / BuildConfig,找不到原因:

多DEX文件定义<我的包> / BuildConfig,找不到原因:

问题描述:

我使用的是新的摇篮构建系统,我面临着以下问题:

I'm using the new gradle build system and I'm facing the following problem:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/kibo/mobi/BuildConfig;
    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)

Priniting依赖我什么都看不到,在这里,他们分别是:

Priniting the dependencies I can't see anything, here they are:

 firstDebugCompile - ## Internal use, do not manually configure ##
 \--- KiboGradle:KiboSDK:unspecified
 +--- KiboGradle:TextInputAPI:unspecified
 +--- KiboGradle:VoiceImeUtils:unspecified
 +--- com.google.android.gms:play-services:5.0.77
 |    \--- com.android.support:support-v4:19.1.0
 +--- com.squareup.picasso:picasso:2.3.2
 +--- com.google.code.gson:gson:2.2.4
 \--- com.crittercism:crittercism-android-agent:4.5.1

我试图验证该问题不重复支持库,所以我想补充一下:

I tried to verify that the problem is not a duplicate support library so I tried to add:

compile ('com.google.android.gms:play-services:5.0.77'){
    exclude module: 'support-v4'
}

导致的错误,有些支持-V4 库类的都找不到,所以这个库没有得到来自任何其他位置进行编译。

Which resulted in errors that some of the support-v4 library classes can't be found, so this library not getting compiled from any other location.

一件事,我脑子里想的,可能会导致这个问题,我使用了的事实香料 feautre在oreder创建几个版本,我用不同的国土资源文件的应用程序。

One thing I had in mind that could cause this problem is the fact that I using the Flavors feautre in oreder to create several versions of my application with different resourse files.

当我看到这是在我看到这个错误的文件:

And when I look at the file that is in the error I see this:

**
* Automatically generated file. DO NOT MODIFY
*/
package com.kibo.mobi;

public final class BuildConfig {
  public static final boolean DEBUG = Boolean.parseBoolean("true");
  public static final String PACKAGE_NAME = "com.kibo.mobi.test.official";
  public static final String BUILD_TYPE = "debug";
  public static final String FLAVOR = "liverpool";
  public static final int VERSION_CODE = 1;
  public static final String VERSION_NAME = "1.0";
}

因此​​,包中的文件,并在字符串值指定的包的是不一样的。

So the package in of the file and the package specified in String value are not the same.

有人能看到我在配置中的任何问题,可能会导致这个问题?

Can anyone see any issues in my configuration that could cause this problem?

在我的情况下,类似的错误发生,因为有2个模块,在AndroidManifest.xml中文件相同的包名。在模块使用不同的包名解决了这个问题。

In my case the similar error happened because there were 2 modules with the same package name in AndroidManifest.xml files. Using different package names in the modules solved the problem.

此外,当一个库JAR被包括两次(或多次)的几个模块,作为一个依赖同样的事情发生。在这种情况下,错误信息有关该库的包名命名重复的configs说。予解决它与包括库作为一个模块的依赖关系,以及第二模块已经在依赖第一模块

Also the same thing happens when a library jar is being included twice (or more times) in several modules, as a dependency. In this case error message says about duplicate configs named after that library's package name. I solved it with including the library as a dependency in one module, and the second module had in dependencies the first module.