0

I'm new to android so please bear with me if its a noob question.

Gradle builds fine but I get this exception when running my app on device.

I'm just trying to support API 21 through 23 and so during that upgrade to by libraries, I ended up with this exception. I can't seem to resolve it. Please help!

**Exception** 

    FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:preDexDebug'.
    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:42)
    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.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:305)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
Caused by: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
    at com.android.ide.common.internal.WaitableExecutor.waitForTasksWithQuickFail(WaitableExecutor.java:116)
    at com.android.ide.common.internal.WaitableExecutor$waitForTasksWithQuickFail$0.call(Unknown Source)
    at com.android.build.gradle.tasks.PreDex.taskAction(PreDex.groovy:106)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:235)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:211)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:222)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:200)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
    ... 13 more
Caused by: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
    at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:42)
    at com.android.builder.core.AndroidBuilder.preDexLibrary(AndroidBuilder.java:1296)
    at com.android.builder.internal.compiler.PreDexCache.preDexLibrary(PreDexCache.java:122)
    at com.android.builder.core.AndroidBuilder.preDexLibrary(AndroidBuilder.java:1248)
    at com.android.builder.core.AndroidBuilder$preDexLibrary$5.call(Unknown Source)
    at com.android.build.gradle.tasks.PreDex$PreDexTask.call(PreDex.groovy:150)
    at com.android.build.gradle.tasks.PreDex$PreDexTask.call(PreDex.groovy)
Caused by: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
    at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:365)
    at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:40)
    ... 6 more


BUILD FAILED

Here is my grade file.

apply plugin: 'com.android.application'

android {
//    signingConfigs {
//        config {
//            keyAlias 'smartcheckinrelease'
//            keyPassword 'smartzip'
//            storeFile file('/Users/nlele/projects/apk signature/smartcheckinkeystorerelease.jks')
//            storePassword 'smartzip'
//        }
//    }
    compileSdkVersion 23
    buildToolsVersion '23.0.2'
    defaultConfig {
        applicationId "com.smartzip.smartcheckin"
        minSdkVersion 21
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/notice.txt'
    }
    lintOptions {
        disable 'InvalidPackage'
    }
}

repositories {

    mavenCentral()

}

dependencies {
    // compile 'cn.pedant.sweetalert:library:1.3'
    // turning off this library as it has its own launcher icon causing below build error.
    // Error:Execution failed for task ':app:processDebugResources'.
    //         > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Users/nlele/Library/Android/sdk/build-tools/22.0.1/aapt'' finished with non-zero exit value 1
    compile 'com.commit451:NativeStackBlur:1.0.2'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:23.1.1'
    compile fileTree(dir: 'libs', include: '*.jar', exclude: 'android-support-*.jar')
    compile 'com.jakewharton:butterknife:6.0.0'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'io.reactivex:rxandroid:1.0.1'
    compile 'io.reactivex:rxjava:1.0.14'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.daimajia.easing:library:1.0.1@aar'
    compile 'com.daimajia.androidanimations:library:1.1.3@aar'
    compile 'com.daimajia.slider:library:1.1.2'
    compile 'com.google.android.gms:play-services:8.3.0'
    compile 'com.google.android.gms:play-services-maps:8.3.0'
    //    compile project(':Downloads:JakeWharton-Android-ViewPagerIndicator-8cd549f:library')
    compile 'com.android.support:recyclerview-v7:23.1.1'
    //    compile project(':myviewpagerindicator')
    compile project(':myindicator')
    //    compile project(':MyViewAnimation')
    compile 'com.daimajia.easing:library:1.0.2'
    compile 'com.daimajia.swipelayout:library:1.2.0'
    compile 'com.github.chrisbanes.photoview:library:1.2.3'
    compile project(':MyHelloCharts')
    //    compile 'com.inkapplications.viewpageindicator:library:2.4.3'
    compile project(':MyCircleProgressIndicator')
    compile 'com.getbase:floatingactionbutton:1.9.0'
    compile 'com.facebook.android:facebook-android-sdk:4.5.0'
    compile 'org.apache.httpcomponents:httpmime:4.5.1'
    compile 'org.apache.httpcomponents:httpcore:4.4.4'
    compile 'org.apache.httpcomponents:httpclient:4.5.1'
    compile 'com.google.code.gson:gson:2.3'
    compile 'org.apache.httpcomponents:httpclient-cache:4.5.1'
    compile 'com.amazonaws:aws-android-sdk-mobileanalytics:2.2.2'
    compile 'com.github.gabrielemariotti.cards:cardslib-core:2.1.0'
    compile 'com.github.gabrielemariotti.cards:cardslib-cards:2.1.0'
    compile 'com.github.gabrielemariotti.cards:cardslib-recyclerview:2.1.0'
    compile 'com.rockerhieu:rv-adapter-endless:1.1'
    compile 'net.danlew:android.joda:2.8.2'
    //retrofit Library
    compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
    compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
    compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta2'
    compile project(':AudioRecordLibrary')
    compile 'org.solovyev.android.views:linear-layout-manager:0.5@aar'
    compile 'com.squareup.picasso:picasso:2.5.2'
}
nikhil
  • 1
  • 2

2 Answers2

1

Please include:

defaultConfig {
   multiDexEnabled true
}

taken from Android Studio fails to debug with error org.gradle.process.internal.ExecException

Hope this helps!

Community
  • 1
  • 1
Actiwitty
  • 1,142
  • 1
  • 11
  • 20
0

gradle is actually not building fine. You are not getting a gradle error when doing test builds because it is not trying to compile the dex into an APK file. So you don't actually have any errors in your code.

The issue you are running into (as mentioned by another answer here) is the limit on dex file methods. You have too many libraries to fit into the old dex build, which used a 16-bit integer ID to reference methods. If you exceed that number of methods in your dex build (65,536), then the dex build error occurs (http://developer.android.com/tools/building/multidex.html).

You can do a few things to avoid this problem.

  1. Use multi-dex builds.
  2. Manually remove unused references to libraries until you are below the limit.
  3. Use a tool (Proguard) to remove unused objects/methods until it is below the limit.

Ultimately an update like what you are doing may result in the requirement to use multi-dex builds.

Jim
  • 9,902
  • 1
  • 23
  • 35