当我将google analytics的配置添加到我的Android项目并构建项目时,我收到以下错误:
:app:transformClassesWithDexForDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Ljavax/inject/Inject;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.transform.api.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesWithDexForDebug'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:310)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:90)
at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:54)
at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:28)
at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:49)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
at org.gradle.util.Swapper.swap(Swapper.java:38)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.health.DaemonHealthTracker.execute(DaemonHealthTracker.java:47)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:66)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:71)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.health.HintGCAfterBuild.execute(HintGCAfterBuild.java:41)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:246)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: org.gradle.internal.UncheckedException: com.android.build.transform.api.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
at org.gradle.internal.UncheckedException.throwAsUncheckedException(UncheckedException.java:45)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:78)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:243)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:219)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:230)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:208)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
... 57 more
Caused by: com.android.build.transform.api.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
at com.android.build.gradle.internal.transforms.DexTransform.transform(DexTransform.java:411)
at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:112)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
... 63 more
Caused by: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:42)
at com.android.builder.core.AndroidBuilder.convertByteCode(AndroidBuilder.java:1325)
at com.android.build.gradle.internal.transforms.DexTransform.transform(DexTransform.java:396)
... 65 more
Caused by: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:365)
at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:40)
... 67 more
这是什么意思?如何防止此错误?
答案 0 :(得分:97)
此处游戏稍晚,但最有可能您在应用的build.gradle
文件中列出的相关性问题。
经过大量测试后,我成功地追查了我的问题,并相信这对其他人有帮助。
我不推荐的事情:
除非你有一个绝对的需要来在build.gradle中启用multiDex 不要做,这只是踩过你应用中的底层问题而不是得到它的根源。您也不必要地增加了apk的大小,并且当您的dex文件中存在冲突方法时可能会发生意外崩溃。
需要注意的事项:
检查build.gradle文件中的所有依赖项。您是否引用了包含已包含的依赖项的依赖项?例如,如果您包含appcompat-v7,则不需要包含appcompat-v4,因为v7包含v4中的所有功能。
我实际发现了什么(我的问题导致我的应用超出了我的dex文件中的方法限制)----> GOOGLE PLAY SERVICES
如果您不需要build.gradle
compile 'com.google.android.gms:play-services:8.3.0'
中此行的所有Google Play服务库依赖项保持远程,而只需使用您需要的内容!!
Google有一个全面的库列表,用于有选择地编译 here
尽管如此,您可能只需要在Gradle中为Google Analytics包含这一行:
dependencies{
compile 'com.google.android.gms:play-services-analytics:8.3.0'
}
修改强>
此外,您可以通过转到项目的根目录(或使用Android工作室中的终端)并运行来查看依赖关系树:
./gradlew app:dependencies
祝你好运,编码愉快!
<强>更新强>
现在,从Android Studio 2.2开始,无论您是否需要在应用程序中使用multi-dex,都不再需要反复试验。使用Apk Analyzer查看是否真的需要它!
答案 1 :(得分:12)
解释: Building Apps with Over 65K Methods
Android应用程序(APK)文件包含Dalvik可执行文件(DEX)文件形式的可执行字节码文件,其中包含用于运行应用程序的已编译代码。 Dalvik可执行规范将单个DEX文件中可引用的方法的总数限制为65,536 ,包括您自己的代码中的Android框架方法,库方法和方法。超过此限制要求您配置应用程序构建过程以生成多个DEX文件,称为多索引配置。
注意:强> 这允许您引用应用程序的所有方法。就好像你有两个模块(限制:2 x 65K)但是压缩成一个模块。这需要构建过程中的成本(时间)。
解决方案:
android { ... defaultConfig { ... multiDexEnabled true } }
答案 2 :(得分:5)
对我来说,这与改造2的simplexml转换器有关。它由:
修复 compile ("com.squareup.retrofit2:converter-simplexml:2.0.0-beta4"){
exclude module: 'stax'
exclude module: 'stax-api'
exclude module: 'xpp3'}
答案 3 :(得分:3)
针对Android 5.0及更高版本的Multidex支持
Android 5.0及更高版本本身使用名为ART的运行时 支持从应用程序APK文件加载多个dex文件。艺术 在扫描的应用程序安装时执行预编译 classes(.. N).dex文件并将它们编译成单个.oat文件 由Android设备执行。有关Android的更多信息 5.0运行时,请参阅ART简介。
这意味着您的应用可以在API级别21或更高级别上正常运行。
Android 5.0之前的Multidex支持
Android 5.0之前的平台版本使用Dalvik运行时 用于执行应用程序代码默认情况下,Dalvik将应用程序限制为单个 每个APK的classes.dex字节码文件。为了解决这个问题 限制,你可以使用multidex支持库,它成为 应用程序的主要DEX文件的一部分,然后管理对其的访问 附加的DEX文件及其包含的代码。
所以,首先要确保你已经导入了正确的依赖,这似乎是你做的。
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
在清单中,将multidex支持库中的MultiDexApplication
类添加到应用程序元素。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
替代方案,如果您的应用扩展了Application
课程,则可以覆盖attachBaseContext()
方法并致电MultiDex.install(this)
以启用multidex
。
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
最后,您需要通过添加multiDexEnabled true
来更新build.gradle文件,如下所示:
defaultConfig {
applicationId '{Project Name}'
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
我希望它会帮助你。
答案 4 :(得分:2)
在我的情况下,我在build.grade文件中有两次
Mail Delivery Status Report will be mailed to ...
我删除第二个条目后,工作正常。
答案 5 :(得分:2)
与我遇到的问题完全相同!
我发现这是由于重复的依赖关系。在build.gradle中,一个依赖项可能已经包含在其他依赖项中,从而产生冲突。我删除了必要的依赖项并解决了我的问题。
答案 6 :(得分:1)
我要解决的问题是从此处(https://developers.google.com/analytics/devguides/collection/android/v4/)删除了gradle更改,然后在Android Studio中进入了&#39;文件/项目结构&#39;然后点击进入分析,如果选中该框,则取消选中它,让gradle sync然后再次选中该框,然后单击按钮进行登录。完成所有这些后,为了让您的分析跟踪器正常工作,您只需将实际跟踪器ID复制到{{ 1}}查看此页面寻求帮助。 https://developers.google.com/android/reference/com/google/android/gms/analytics/GoogleAnalytics
答案 7 :(得分:1)
在构建文件中包含特定的依赖项。
如果您想将地图添加到您的应用中,则 包含 编译 '的 com.google.android.gms:玩服务-位置:9.2.1 强>
代替编译' com.google.android.gms:play-services:9.2.1 '
答案 8 :(得分:0)
我认为您正在使用谷歌分析sdk V3使用V4而我在使用谷歌分析https://developers.google.com/analytics/devguides/collection/android/v4/的sdk V3时也面临同样的问题。请参阅此链接以获取更多信息。
答案 9 :(得分:0)
如果您将Android Studio更新到最新版本1.4,则可能会发生这种情况。您是否将支持库更新到最新版本?您的apply plugin: 'com.android.application'
android {
compileSdkVersion 23 //update this to 23
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "your.package.name"
minSdkVersion 16
targetSdkVersion 21
multiDexEnabled true //enable this
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
// update these to 23 if you have them and add the multidex
compile 'com.android.support:support-v4:23.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:multidex:1.0.1'
}
应为23。
{{1}}
答案 10 :(得分:0)
我实际上发现有太多的Android Studio模块导致在没有启用multidex的情况下出现此错误。如果您试图避免启用multidex,那么限制似乎大约是26个模块。这是Android Studio 1.5.1
答案 11 :(得分:0)
答案 12 :(得分:0)
从Android开发者网站上:
Android 5.0(API级别21)及更高版本使用称为ART的运行时,它天真地支持从APK文件加载多个DEX文件。
我已将min SDK设置为21,它为我解决了这个问题(当然,如果您将min-SDK设置为21或更高,当然需要检查您的具体情况)