Java 多个dex文件定义了<my package>/BuildConfig,找不到原因:
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25103288/
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 <my package>/BuildConfig, can't find the cause:
提问by Emil Adz
I'm using the new gradle build system and I'm facing the following problem:
我正在使用新的 gradle 构建系统,但面临以下问题:
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'
}
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.
这导致support-v4
无法找到某些库类的错误,因此无法从任何其他位置编译此库。
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.
我想到的可能导致此问题的一件事是,我在Flavors
oreder 中使用 feautre 来创建具有不同资源文件的应用程序的多个版本。
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.
所以文件的包in和String值指定的包是不一样的。
Can anyone see any issues in my configuration that could cause this problem?
任何人都可以看到我的配置中可能导致此问题的任何问题吗?
回答by iceman
Add this to your build.gradle:
将此添加到您的 build.gradle 中:
android {
dexOptions {
preDexLibraries = false
}
}
I suppose this way there is no conflicting BuildConfig.java
.
我想这样就没有冲突了BuildConfig.java
。
EDIT:
编辑:
Why the above works:
Android studio will first dexthe libraries before dex-ing the app module. If you have a library module with a same package name as your app module, this 'pre-dexing' will result in creation of a BuildConfig.java
in the same package as for the app.
为什么以上有效:Android Studio 将首先dex库,然后再 dex-ing app 模块。如果您的库模块与您的应用程序模块具有相同的包名称,则此“pre-dexing”将导致在BuildConfig.java
与应用程序相同的包中创建一个。
Not 'pre-dexing' will slow down your build process a bitso I suggest that you change your library's package name instead.
不是 'pre-dexing' 会减慢你的构建过程,所以我建议你改为更改库的包名称。
回答by Mixaz
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.
就我而言,发生类似错误是因为 AndroidManifest.xml 文件中有 2 个具有相同包名的模块。在模块中使用不同的包名解决了这个问题。
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.
当一个库 jar 作为依赖项被包含在多个模块中两次(或多次)时,也会发生同样的事情。在这种情况下,错误消息说关于以该库的包名称命名的重复配置。我通过将库作为依赖项包含在一个模块中解决了这个问题,而第二个模块依赖于第一个模块。
回答by Steve D.
For me, simply doing a clean on the project cleared this error.
对我来说,只需对项目进行清理即可清除此错误。
回答by Pablo Cegarra
I was getting this problem signing my instantapk. The problem:
我在签署我的即时apk时遇到了这个问题。问题:
bad module/app/manifest.xml
坏模块/应用程序/manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.stackoverflow">
good: module/app/manifest.xml
好:模块/应用程序/manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.stackoverflow.app">
Just adding the .app at the end of the package name
只需在包名末尾添加 .app
回答by Sami
If using NewRelic, then update it to at least 5.21.1
.
如果使用 NewRelic,则将其至少更新为5.21.1
.