【问题标题】:Error:Execution failed for task ':app:dexDebug'.错误:任务“:app:dexDebug”执行失败。
【发布时间】:2016-12-13 09:27:30
【问题描述】:

当我尝试在手机上运行我的应用时,我收到以下错误

错误:任务 ':app:dexDebug' 执行失败。 com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_65\bin\java.exe'' 完成非零退出值 2

我对编程比较陌生,所以从做一些研究来看,这可能是因为重复的库或超出了内存。所以我尝试了几个建议的选项,比如从依赖项中删除这一行

编译fileTree(dir: 'libs', include: ['*.jar'])

还将这些添加到 build.gradle(app) 文件中

默认配置 { ... ... multiDexEnabled 真 }

dexOptions { preDexLibraries = 假 javaMaxHeapSize "4g" }

Gradle 同步很好,问题是当我尝试在手机上运行时。我可以很好地在 Android Studio 中运行其他应用程序,只是这个特定的应用程序。如果有重复的库,我该如何检查以及哪些是重复的?

gradle文件如下

应用插件:'com.android.application'

机器人{ compileSdkVersion 23 buildToolsVersion "23.0.3"

defaultConfig {
    applicationId "com.myweb.MyApp"
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

依赖{ 编译 fileTree(dir: 'libs', include: ['*.jar']) 测试编译'junit:junit:4.12' 编译'com.android.support:appcompat-v7:23.2.1' 编译'com.android.support:design:23.2.1'

/*Added*/
compile 'com.google.firebase:firebase-database:9.4.0'
compile 'com.firebaseui:firebase-ui:0.4.3'
compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.firebase:firebase-client-android:2.5.2'

} 应用插件:'com.google.gms.google-services'

和 gradle 控制台日志

执行任务:[:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:assembleDebug]

按需配置是一项孵化功能。 :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :app:prepareComAndroidSupportAnimatedVectorDrawable2400Library UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72400Library UP-TO-DATE :app:prepareComAndroidSupportCardviewV72321Library UP-TO-DATE :app:prepareComAndroidSupportCustomtabs2321Library UP-TO-DATE :app:prepareComAndroidSupportDesign2400Library UP-TO-DATE :app:prepareComAndroidSupportRecyclerviewV72400Library UP-TO-DATE :app:prepareComAndroidSupportSupportV42400Library UP-TO-DATE :app:prepareComAndroidSupportSupportVectorDrawable2400Library UP-TO-DATE :app:prepareComFacebookAndroidFacebookAndroidSdk4110Library UP-TO-DATE :app:prepareComFirebaseuiFirebaseUi043Library UP-TO-DATE :app:prepareComFirebaseuiFirebaseUiAuth043Library UP-TO-DATE :app:prepareComFirebaseuiFirebaseUiDatabase043Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesAuth921Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesAuthBase921Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesBase940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesBasement940Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesTasks940Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseAnalytics940Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseAnalyticsImpl940Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseAuth921Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseAuthCommon921Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseAuthModule921Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseCommon940Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseCore940Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseDatabase940Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseDatabaseConnection940Library UP-TO-DATE :app:prepareComGoogleFirebaseFirebaseIid940Library UP-TO-DATE :app:prepareDebugDependencies :app:compileDebugAidl 最新 :app:compileDebugRenderscript 最新 :app:generateDebugBuildConfig 最新 :app:generateDebugAssets 最新 :app:mergeDebugAssets 最新 :app:generateDebugResValues 最新 :app:processDebugGoogleServices 解析json文件:C:\Users\Admin\AndroidStudioProjects\MyApp\app\google-services.json :app:generateDebugResources :app:mergeDebugResources 最新 :app:processDebugManifest 最新 :app:processDebugResources 最新 :app:generateDebugSources 最新 :app:preDebugAndroidTestBuild UP-TO-DATE :app:prepareDebugAndroidTestDependencies :app:compileDebugAndroidTestAidl 最新 :app:processDebugAndroidTestManifest 最新 :app:compileDebugAndroidTestRenderscript UP-TO-DATE :app:generateDebugAndroidTestBuildConfig UP-TO-DATE :app:generateDebugAndroidTestAssets UP-TO-DATE :app:mergeDebugAndroidTestAssets 最新 :app:generateDebugAndroidTestResValues UP-TO-DATE :app:generateDebugAndroidTestResources UP-TO-DATE :app:mergeDebugAndroidTestResources 最新 :app:processDebugAndroidTestResources 最新 :app:generateDebugAndroidTestSources 最新 :app:processDebugJavaRes 最新 :app:compileDebugJavaWithJavac 最新 :app:compileDebugNdk 最新 :app:compileDebugSources 最新 :app:preDexDebug 最新 :app:dexDebug AGPBI: {"kind":"simple","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","sources":[{}]} AGPBI: {"kind":"simple","text":"com.android.dex.DexException: 多个 dex 文件定义 Lcom/google/android/gms/internal/zzaga;","sources":[{}] } AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)","sources":[{}]} AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)","sources":[{}]} AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)","sources":[{}]} AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)","sources":[{}]} AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:188)","sources":[{}]} AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)","sources":[{}]} AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)","sources":[{}]} AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.run(Main.java:277)","sources":[{}]} AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.main(Main.java:245)","sources":[{}]} AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.Main.main(Main.java:106)","sources":[{}]}

失败

FAILURE:构建失败并出现异常。

  • 出了什么问题: 任务 ':app:dexDebug' 执行失败。

    com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_65\bin\java.exe'' 完成非零退出值 2

  • 尝试: 使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。

构建失败

总时间:8.719 秒

【问题讨论】:

    标签: android android-studio android-gradle-plugin


    【解决方案1】:

    您的项目中可能有重复的 jar/libraries将您的 gradle 文件更改为:

    compile 'com.google.firebase:firebase-database:9.4.0'
    compile 'com.firebaseui:firebase-ui:0.4.3'
    compile 'com.google.firebase:firebase-core:9.4.0'
    compile 'com.firebase:firebase-client-android:2.5.2'
    

    喜欢这样:

    compile 'com.google.firebase:firebase-database:9.4.0'
    compile 'com.google.firebase:firebase-core:9.4.0'
    

    还要检查项目中的任何其他 jar/库重复。

    【讨论】:

    • 也可以查看这个帖子:stackoverflow.com/questions/28917696/…
    • 我玩弄了这些库,它实际上是由“compile 'com.firebase:firebase-client-android:2.5.2'”引起的,我删除了它并且它起作用了
    【解决方案2】:

    我已经弄清楚了,实际上问题是由

    引起的

    编译'com.firebase:firebase-client-android:2.5.2'

    自从它是一个旧图书馆以来,我已将其删除, 我认为是

    编译'com.google.firebase:firebase-database:9.4.0'

    这是自 Firebase 根据 this article 的第 3 点更改后的新库

    改成这样:

    compile 'com.google.firebase:firebase-database:9.4.0'
    compile 'com.google.firebase:firebase-core:9.4.0'
    compile 'com.firebaseui:firebase-ui:0.4.4'
    

    【讨论】:

      【解决方案3】:

      跑步

      cd android && ./gradlew clean
      

      从根目录解决问题。

      【讨论】:

        猜你喜欢
        • 2015-05-16
        • 2015-05-09
        • 1970-01-01
        • 2016-04-03
        • 2016-06-27
        • 1970-01-01
        相关资源
        最近更新 更多