Gradle 发布构建失败

Gradle release build fails

我正在为我的项目使用此配置:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

repositories {
    mavenCentral()
    maven { url "https://jitpack.io" }
}

android {
    signingConfigs {
        config {
            keyAlias XXXXXXX
            keyPassword XXXXXXXX
            storePassword XXXXXXXXXX
            storeFile file('/../XXXXXXXXXXX')
        }
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    defaultConfig {
        applicationId "com.example"
        minSdkVersion 10
        targetSdkVersion 20
        versionCode 9
        versionName "18.6"
        multiDexEnabled true
        signingConfig signingConfigs.config
    }
    buildTypes {
        release {
            minifyEnabled false
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'LICENSE.txt'
    }
    productFlavors {
    }

    lintOptions {
        abortOnError false
    }
    dexOptions {
        preDexLibraries = false
    }
    defaultConfig{
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
}

afterEvaluate {
    tasks.matching {
        it.name.startsWith('dex')
    }.each { dx ->
        if (dx.additionalParameters == null) {
            dx.additionalParameters = ['--multi-dex']
        } else {
            dx.additionalParameters += '--multi-dex'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.6.0'
    compile 'com.fasterxml.jackson.core:jackson-core:2.6.0'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.6.0'
    compile 'com.android.support:support-v4:23.0.0'
    compile 'com.journeyapps:zxing-android-embedded:3.0.0@aar'
    compile 'com.google.zxing:core:3.2.0'
    compile 'com.google.android.gms:play-services-analytics:8.3.0'
    compile "com.google.android.gms:play-services-gcm:8.3.0"
    compile 'com.github.flavienlaurent.datetimepicker:library:+'
    compile 'com.roomorama:caldroid:2.2.0'
    compile 'org.mozilla:rhino:+'
    compile 'org.roboguice:roboguice:3.+'
    provided 'org.roboguice:roboblender:3.+'
    compile 'com.cocosw:favor:0.1.0@aar'
    compile 'com.github.orhanobut:logger:1.12'
    compile files('libs/universal-image-loader-1.9.4.jar')
    compile files('libs/mail.jar')
    compile files('libs/activation.jar')
    compile files('libs/additionnal.jar')

    // Testing-only dependencies
    // Force usage of support annotations in the test app, since it is internally used by the runner module.
    androidTestCompile 'com.android.support:support-annotations:23.1.1'
    androidTestCompile 'com.android.support.test:runner:0.4.1'
    androidTestCompile 'com.android.support.test:rules:0.4.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
    androidTestCompile 'com.android.support:support-annotations:23.1.1'
}

堆栈跟踪:

 org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesWithDexForRelease'.
        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:52)
        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.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
        at org.gradle.internal.concurrent.StoppableExecutorImpl.run(StoppableExecutorImpl.java:40)
Caused by: java.lang.RuntimeException: com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
        at com.android.builder.profile.Recorder$Block.handleException(Recorder.java:54)
        at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:57)
        at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:47)
        at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:173)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:244)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:220)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:231)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:209)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
        ... 14 more
Caused by: com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
        at com.android.build.gradle.internal.transforms.DexTransform.transform(DexTransform.java:421)
        at com.android.build.gradle.internal.pipeline.TransformTask.call(TransformTask.java:178)
        at com.android.build.gradle.internal.pipeline.TransformTask.call(TransformTask.java:174)
        at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:55)
        ... 23 more
Caused by: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
        at com.android.builder.core.AndroidBuilder.dexInProcess(AndroidBuilder.java:1513)
        at com.android.builder.core.AndroidBuilder.runDexer(AndroidBuilder.java:1488)
        at com.android.builder.core.AndroidBuilder.convertByteCode(AndroidBuilder.java:1477)
        at com.android.build.gradle.internal.transforms.DexTransform.transform(DexTransform.java:251)
        ... 26 more
Caused by: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
        at com.android.builder.core.AndroidBuilder.dexInProcess(AndroidBuilder.java:1502)
        ... 29 more
Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded

当我在 Android studio 中以调试模式尝试 运行 代码时,一切正常,但当我尝试发布代码时,它只是卡在 dexing 阶段,我得到 OutOfMemoryException。我尝试使用更多 RAM 进行编译(8g,但它只会持续更长时间并再次失败)。我还尝试在 API 21 和其他 Android 工作室版本上编译它,但没有成功。我正在使用 Android studio 2.0,稳定版。谁能帮我解决这个问题?

问题出在 Java 版本上。我更新Android studio的时候,没有运行发布,没注意,但是Java切换到1.8版本,不支持了。当我恢复到较低版本时,一切都重新开始工作。右键单击项目 > 模块设置 > Java 并将其设置在那里。