简体   繁体   中英

AndroidStudio: Gradle build failed for task 'app:preDexDebug (ProcessException, ExecException, non-zero exit value 1)

Iam able to build and run the whole project without any problems if I have minSdkVersion set to 17, but if I set minSdkVersion to 21 it gives me the following error, if I try to run the app (building still works fine).

I have read all the other suggestions about solving this problem, eg Cannot build android project using Android Studio - Gradle 1.7 but it did not solve my problem.

I started gradle with --debug and it gives me the output:

20:39:10.077 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTING
20:39:10.078 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Waiting until process started: command 'C:\Program Files\Java\jdk1.8.0_31\bin\java.exe'.
20:39:10.129 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTED
20:39:10.129 [DEBUG] [org.gradle.process.internal.ExecHandleRunner] waiting until streams are handled...
20:39:10.244 [INFO] [org.gradle.process.internal.DefaultExecHandle] Successfully started process 'command 'C:\Program Files\Java\jdk1.8.0_31\bin\java.exe''
20:39:10.246 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: FAILED
20:39:10.247 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Process 'command 'C:\Program Files\Java\jdk1.8.0_31\bin\java.exe'' finished with exit value 1 (state: FAILED)
20:39:10.254 [INFO] [org.gradle.api.Project] processing archive D:\Benutzer\Henrik\Eigene Dokumente\Project\app\build\intermediates\exploded-aar\com.google.android.gms\play-services-appstate\8.1.0\jars\classes.jar...
ignored resource META-INF/
ignored resource META-INF/MANIFEST.MF


20:39:10.255 [ERROR] [org.gradle.api.Project] AGPBI: {"kind":"SIMPLE","text":"no classfiles specified","position":{},"original":"no classfiles specified"}


20:39:10.271 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':app:preDexDebug'
20:39:10.271 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :app:preDexDebug FAILED
20:39:10.272 [INFO] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] :app:preDexDebug (Thread[Daemon worker Thread 12,5,main]) completed. Took 1 mins 25.716 secs.
20:39:10.272 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[Daemon worker Thread 12,5,main]] finished, busy: 1 mins 32.723 secs, idle: 0.088 secs

20:39:10.277 [ERROR] [org.gradle.BuildExceptionReporter] 
20:39:10.277 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
20:39:10.277 [ERROR] [org.gradle.BuildExceptionReporter] 
20:39:10.278 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
20:39:10.278 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':app:preDexDebug'.
20:39:10.278 [ERROR] [org.gradle.BuildExceptionReporter] > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_31\bin\java.exe'' finished with non-zero exit value 1
20:39:10.278 [ERROR] [org.gradle.BuildExceptionReporter] 
20:39:10.278 [ERROR] [org.gradle.BuildExceptionReporter] * Try:
20:39:10.278 [ERROR] [org.gradle.BuildExceptionReporter] Run with --stacktrace option to get the stack trace. 

20:39:10.279 [LIFECYCLE] [org.gradle.BuildResultLogger] 
20:39:10.279 [LIFECYCLE] [org.gradle.BuildResultLogger] BUILD FAILED
20:39:10.279 [LIFECYCLE] [org.gradle.BuildResultLogger] 
20:39:10.279 [LIFECYCLE] [org.gradle.BuildResultLogger] Total time: 1 mins 38.519 secs

build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "de.project.test"
        minSdkVersion 21
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile 'com.android.support:design:23.0.1'
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.google.android.gms:play-services:8.1.0'
    compile 'com.hannesdorfmann.mosby:mvp:2.0.0'
    compile 'com.hannesdorfmann.mosby:viewstate:2.0.0'
    compile 'com.google.guava:guava:18.0'
    // Dagger 2 and Compiler
    compile 'com.google.dagger:dagger:2.0.1'
    apt "com.google.dagger:dagger-compiler:2.0.1"
    compile 'javax.annotation:jsr250-api:1.0'
}

UPDATE If I delete all usages of 'com.google.android.gms:play-services:8.1.0' and the compile entry in the build-file it runs. So it runs if I don´t use 'com.google.android.gms:play-services:8.1.0' or if I set minSDK to 17, but this could not be the solution. Does anyone has an idea how I can use minSDK 21 and use the play-services especially google-maps?

Finally I found a "solution" which worked for me.

Looking at the output from gradle (running with --debug) you can see the last INFO before the ERROR occurs is:

20:39:10.254 [INFO] [org.gradle.api.Project] processing archive D:\Benutzer\Henrik\Eigene Dokumente\Project\app\build\intermediates\exploded-aar\com.google.android.gms\play-services-appstate\8.1.0\jars\classes.jar...

I excluded this module (play-services-appstate, whatever it does) in build.gradle and it works.

compile ('com.google.android.gms:play-services:8.1.0'){
    exclude module: 'play-services-appstate'
}

alternativly if you don´t need the whole play-services-library, eg just google-maps, you can change

compile 'com.google.android.gms:play-services:8.1.0'

to

compile 'com.google.android.gms:play-services-maps:8.1.0'

which has also worked for me.

So if you have the same error, I would recommend to run gradle with --debug and exclude the module which is named before the error occurs (if you can). The preDexDebug failure is really tricky. There could be many reasons (dependencies, java-version, ...), so I would recommend to also have a look at the many other stackoverflow-questions about this failure.

However, if anyone has an idea, I would still be interested in identifying the real problem with the module I have excluded from build.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM