Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To run dex in process, the Gradle daemon needs a larger heap. It currently has 910 MB

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.

like image 363
Däñish Shärmà Avatar asked Feb 05 '16 12:02

Däñish Shärmà


People also ask

How much RAM do you want to allocate to Gradle?

512MB is more than enough for most builds. Larger builds with hundreds of subprojects, lots of configuration, and source code may require, or perform better, with more memory.

How do I give more memory to Gradle?

For faster builds, increase the maximum heap size for the Gradle daemon to more than 2048 MB. To do this set org. gradle. jvmargs=-Xmx2048M in the project gradle.

How do I clean up Gradle daemons?

Go To C:\Users\"Username"\. gradle\daemon. There are a Folder for each version of gradle. Delete the folder of your actual running version Check with --status.

What is org Gradle Jvmargs?

org.gradle.jvmargs - specifies jvmargs used for daemon process. You want to set high enough memory limit to fix dex in Gradle process, so minimum configuration here is -Xmx2g , while 3-4 gigabytes won't hurt either.


3 Answers

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.

like image 195
Eugen Pechanec Avatar answered Sep 28 '22 05:09

Eugen Pechanec


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.+'
}
like image 39
Däñish Shärmà Avatar answered Sep 28 '22 05:09

Däñish Shärmà


try this gradle params

defaultConfig {
    ...

    // Enabling multidex support.
    multiDexEnabled true
}
like image 30
Станислав Полозов Avatar answered Sep 28 '22 06:09

Станислав Полозов