Gradle Build失败 - Java.exe以非零退出值2结束

Zoo*_*key 4 android gradle build.gradle android-gradle-plugin

我添加了recyclerview gradle build,然后尝试运行应用程序,现在我收到此错误:

错误:任务':app:dexDebug'的执行失败.

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

这是我的gradle构建文件:

dependencies {
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:22.1.1'
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
compile 'com.parse.bolts:bolts-android:1.2.0'
compile 'com.android.support:design:22.2.0'
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.facebook.fresco:fresco:0.5.2+'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile fileTree(dir: 'libs', include: 'commons-io-*.jar')
compile fileTree(dir: 'libs', include: 'ParseFacebookUtilsV4-*.jar')
}
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题?

Dav*_*ker 8

看起来您已达到dex限制,并且您的应用程序中有超过65k的方法.

如果你想保持所有的gradle依赖关系,你应该考虑配置multidex,它将使用多个dex文件构建你的应用程序.

另一种解决方案是尝试从Google Play服务库中删除任何不必要的依赖项.您可能无需包含所有内容,您可以选择仅添加所需的导入.

例如:

com.google.android.gms:play-services-maps:7.5.0
com.google.android.gms:play-services-gcm:7.5.0
Run Code Online (Sandbox Code Playgroud)

而不是简单地使用:

compile 'com.google.android.gms:play-services:7.5.0'
Run Code Online (Sandbox Code Playgroud)

您可以参考Google Play服务指南来确定应添加哪些库.