我不想开始一个与此问题相关的新问题,因为我知道已经有一些问题,但我仍然没有找到解决方案,而且我很困难。
我目前收到错误:
错误:任务':app:transformClassesWithDexForDebug'执行失败。
com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:Process' command' / Library /的Java / JavaVirtualMachines / jdk1.7.0_79.jdk /内容/首页/斌/ java的''完成非零退出值2
这就是Gradle控制台的显示效果
意外的顶级异常:com.android.dex.DexException:多个dex文件定义Lbolts / AggregateException;在 com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579) 在com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535) 在com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517) 在com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)at at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504) 在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)
FAILED
失败:构建因异常而失败。
出了什么问题:任务执行失败':app:transformClassesWithDexForDebug'。
com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException:进程'命令 ' /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' 完成非零退出值2
尝试:使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获得更多日志输出。
建立失败
这是我的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.andrewnwalker.mousetimes_california"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.parse.bolts:bolts-android:1.+'
compile fileTree(dir: 'libs', include: ['Parse-*.jar'])
compile files('libs/Parse-1.12.0.jar')
compile files('libs/bolts-tasks-1.3.0.jar')
compile files('libs/universal-image-loader-1.9.5.jar')
compile files('libs/joda-time-2.9.1.jar')
}
我已经尝试过所有明显的事情,比如清洁,重建,开/关。我还尝试删除一些依赖项,看看是否会产生影响。
据我所知,自从它工作正常以来,我没有做任何改变。我很确定我连续第二次运行该项目并出现错误。我可能错了。
有人有任何建议吗?
答案 0 :(得分:1)
最近,我遇到了同样的问题,这是我的解决方案,有两个步骤:
顶级Gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
classpath 'com.google.gms:google-services:2.0.0-alpha3'//for any google libs
}
}
allprojects {
repositories {
jcenter()
}
}
模块(app)级别Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "your_app_id"
minSdkVersion 9
targetSdkVersion 22
// Enabling multidex support can also help (uncomment and test)
//multiDexEnabled true
}
buildTypes {
release {
//minifyEnabled true
//shrinkResources true
proguardFiles 'proguard-project.txt'
}
}
}
dependencies {
//your dependencies
}
apply plugin: 'com.google.gms.google-services' **//Place this line at the end if you use any google service lib.**
答案 1 :(得分:0)
像这样更新你的顶级gradle,
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
classpath 'com.google.gms:google-services:2.0.0-alpha3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
像这样更新你的app level gradle,
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
// package name, target sdk and version code as per your code
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
// your libraries here
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:multidex:1.0.1'
}
apply plugin: 'com.google.gms.google-services'
并像这样更新您的Android清单文件,
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:name="android.support.multidex.MultiDexApplication"
android:theme="@style/AppTheme">
并将此行添加到onCreate函数中的启动器活动中。
MultiDex.install(this);
看看是否有效。