18

Actually the main error is "java.exe finished with non-zero exit value 1". First i tell you every problem which i faced after installing studio:

Three days ago, i just installed android studio & I created new project.

1) First it throw the error "Plugin is too old, please update to more recent version", after searching on google i changed

classpath : com.android.tools.build:gradle:2.0.0-alpha2

to

classpath : com.android.tools.build:gradle:2.0.0-alpha8

Current Error solved.

2) After that it was asking for gradle 2.10, i updated this one also & set the path. enter image description here Current Error solved.

3) When i ran my application i got one more error "app-debug-unaligned.apk, specified for property 'input file' does not exist".

I searched on internet, i got one solution on stackoverflow. So as answer on stackoverflow i go to "Build" & i selected build apk.

Current error solved.

4) But after that again i got one error

"To run dex in process, the Gradle daemon needs a larger heap. It currently has 910 MB. For faster builds, increase the maximum heap size for the Gradle daemon to more than 1G.

java.exe finished with non-zero exit value 1".

I have been searching on stackoverflow for last three days, i applied each and every answer one by one but i'm not able to solve the error. Please save my life, i am really tired of this problem. I show you image what error is coming exactlyenter image description here

My build.gradle file

apply `plugin: com.android.application`

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "java.danish.org.myapplication"
        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'
}

I updated everything SDK platforms & SDk Tools.enter image description here

enter image description here

Please tell me what i am doing wrong here.

gauravsheohar
  • 396
  • 5
  • 12
Däñish Shärmà
  • 2,891
  • 2
  • 25
  • 43

3 Answers3

29

Issue

In gradle plugin version 2.0.0-alpha7 and -alpha8 Dex runs inside gradle build process as opposed to a separate process.

Option a)

Change gradle plugin version to 2.0.0-alpha9 where in-process Dex is disabled by default.

classpath 'com.android.tools.build:gradle:2.0.0-alpha9'

Option b)

Disable in-process dex in your app module build.gradle:

android {
    // ...
    dexOptions {
        dexInProcess = false
    }
}

Option c)

Increase memory available to gradle process.

Create or update gradle.properties file in your project root directory:

# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=512m

And update your app module build.gradle file:

dexOptions {
    preDexLibraries true
    javaMaxHeapSize "3g"
    incremental true
    dexInProcess = true
}

These values are experimental and work for my setup. I use 3 GB for dex and 4 GB for gradle (3 + 1 GB).

Note

If you have any issues update to alpha9 anyway.

Eugen Pechanec
  • 37,669
  • 7
  • 103
  • 124
  • 2
    @DäñishShärmà While at it you can try -beta2 which just rolled out. http://tools.android.com/recent/androidstudio20beta2availableincanarychannel If nothing works, trry going back to 1.5.0. You won't get Instant Run but I find it unreliable for production work yet. – Eugen Pechanec Feb 05 '16 at 12:46
  • thanks alot. Your answer didn't work but your idea is working. Actually the problem was with studio 2.0 and alpha8. Now i'm using studio 1.4 beta 2 & gradle:1.3.0 & everything is fine. Thank you and god bless you. @Eugen – Däñish Shärmà Feb 05 '16 at 15:56
  • Thanks for a detailed answer. Setting multiDexEnabled to true, dexInProcess to false worked for me. Actually dex in process ruined everything after a gradle update. – Nagaraju Gajula Sep 07 '16 at 14:11
6

I found the solution.

Changes 1)

 dexOptions {
            javaMaxHeapSize "4g"
        }

2)

 lintOptions {
            checkReleaseBuilds false
            abortOnError false
        }

This is my new build.gradle and everything is working fine now.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.0 rc4"

    dexOptions {
        javaMaxHeapSize "4g"
    }
    defaultConfig {
        applicationId "com.aquasoft.guesp"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile 'com.android.support:recyclerview-v7:23.3.0'
    compile 'com.squareup.picasso:picasso:2.5.0'
    compile 'com.google.android.gms:play-services:9.0.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.stripe:stripe-android:+'
    compile 'com.roomorama:caldroid:3.0.1'
    compile 'com.android.support:cardview-v7:23.3.+'
}
Däñish Shärmà
  • 2,891
  • 2
  • 25
  • 43
  • 2
    -1. Not only did you not specify what fixed the problem, but somebody else already gave you the answer below and you did not accept their answer. – howettl Aug 30 '16 at 19:31
2

try this gradle params

defaultConfig {
    ...

    // Enabling multidex support.
    multiDexEnabled true
}