多个dex文件定义了<my package>/BuildConfig,找不到原因: [英] Multiple dex files define <my package>/BuildConfig, can't find the cause:

查看:29
本文介绍了多个dex文件定义了<my package>/BuildConfig,找不到原因:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用新的 gradle 构建系统,但面临以下问题:

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 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'
}

导致无法找到某些 support-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.

我想到的可能导致此问题的一件事是,我使用 Flavors feautre 来创建具有不同资源文件的应用程序的多个版本.

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";
}

所以文件的包in和String值指定的包是不一样的.

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?

推荐答案

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

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 作为依赖项被包含在多个模块中两次(或多次)时,也会发生同样的事情.在这种情况下,错误消息说关于以该库的包名称命名的重复配置.我通过将库作为依赖项包含在一个模块中解决了这个问题,而第二个模块依赖于第一个模块.

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.

这篇关于多个dex文件定义了<my package>/BuildConfig,找不到原因:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆