错误:任务':app:dexDebug'。

时间:2016-08-07 14:21:57

标签: android android-studio android-gradle

当我尝试在手机上运行我的应用时出现以下错误

  

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

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

  

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

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

  

defaultConfig {      ...      ...      multiDexEnabled是的   }

  

dexOptions {           preDexLibraries = false           javaMaxHeapSize" 4g"       }

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

gradle文件如下

  

申请插件:' com.android.application'

android {     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'])     testCompile' 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 console log

  

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

按需配置是一项孵化功能。 :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :应用: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 :应用:prepareDebugDependencies :app:compileDebugAidl UP-TO-DATE :app:compileDebugRenderscript UP-TO-DATE :app:generateDebugBuildConfig UP-TO-DATE :app:generateDebugAssets UP-TO-DATE :app:mergeDebugAssets UP-TO-DATE :app:generateDebugResValues UP-TO-DATE :应用:processDebugGoogleServices 解析json文件:C:\ Users \ Admin \ AndroidStudioProjects \ MyApp \ app \ google-services.json :应用:generateDebugResources :app:mergeDebugResources UP-TO-DATE :app:processDebugManifest UP-TO-DATE :app:processDebugResources UP-TO-DATE :app:generateDebugSources UP-TO-DATE :app:preDebugAndroidTestBuild UP-TO-DATE :应用:prepareDebugAndroidTestDependencies :app:compileDebugAndroidTestAidl UP-TO-DATE :app:processDebugAndroidTestManifest UP-TO-DATE :app:compileDebugAndroidTestRenderscript UP-TO-DATE :app:generateDebugAndroidTestBuildConfig UP-TO-DATE :app:generateDebugAndroidTestAssets UP-TO-DATE :app:mergeDebugAndroidTestAssets UP-TO-DATE :app:generateDebugAndroidTestResValues UP-TO-DATE :app:generateDebugAndroidTestResources UP-TO-DATE :app:mergeDebugAndroidTestResources UP-TO-DATE :app:processDebugAndroidTestResources UP-TO-DATE :app:generateDebugAndroidTestSources UP-TO-DATE :app:processDebugJavaRes UP-TO-DATE :app:compileDebugJavaWithJavac UP-TO-DATE :app:compileDebugNdk UP-TO-DATE :app:compileDebugSources UP-TO-DATE :app:preDexDebug UP-TO-DATE :应用:dexDebug AGPBI:{" kind":"简单","文字":"意想不到的顶级例外:","来源& #34;:[{}]} AGPBI:{" kind":"简单","文字":" com.android.dex.DexException:多个dex文件定义Lcom / google /机器人/克/内部/ zzaga;""来源":[{}]} AGPBI:{" kind":" simple"," text":" \ tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger。的java:579)""来源":[{}]} AGPBI:{" kind":" simple"," text":" \ tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger。的java:535)""来源":[{}]} AGPBI:{" kind":" simple"," text":" \ tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger。的java:517)""来源":[{}]} AGPBI:{" kind":" simple"," text":" \ tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger。的java:164)""来源":[{}]} AGPBI:{" kind":" simple"," text":" \ tat com.android.dx.merge.DexMerger.merge(DexMerger。的java:188)""来源":[{}]} AGPBI:{" kind":" simple"," text":" \ tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers( Main.java:504)""来源":[{}]} AGPBI:{" kind":" simple"," text":" \ tat com.android.dx.command.dexer.Main.runMonoDex( Main.java:334)""来源":[{}]} AGPBI:{" kind":" simple"," text":" \ tat com.android.dx.command.dexer.Main.run( Main.java:277)""来源":[{}]} AGPBI:{" kind":" simple"," text":" \ tat com.android.dx.command.dexer.Main.main( Main.java:245)""来源":[{}]} AGPBI:{" kind":" simple"," text":" \ tat com.android.dx.command.Main.main(Main。的java:106)""来源":[{}]}

FAILED

失败:构建因异常而失败。

  • 出了什么问题: 任务':app:dexDebug'。

    执行失败
      

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

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

建立失败

总时间:8.719秒

3 个答案:

答案 0 :(得分:1)

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

引起的
  

编译'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'

答案 1 :(得分:1)

正在运行

cd android && ./gradlew clean

从根目录解决了问题。

答案 2 :(得分:0)

您的项目中可能有重复的 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 /库复制。