Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JVM arguments gradle cannot be set in gradle.properties file for Android Studio 2.1.1

-Running Android 2.1.1 on Mac OS X

-App is not on Android phone.

content of gradle.properties file

org.gradle.jvmargs=-Xmx2048M

enter image description here

When hovering, the IDE indicates it is an unused property. It should also be dark blue instead of grey.

Output:

:MyProjectDirName:transformClassesWithInstantRunSlicerForDebug
:MyProjectDirName:transformClassesWithDexForDebug
To run dex in process, the Gradle daemon needs a larger heap.
It currently has approximately 910 MB.
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.properties.
For more information see   
https://docs.gradle.org/current/userguide/build_environment.html

The output of the compiler clearly indicates it discards the contents of the gradle.properties file.

contents build.gradle

android {
    dexOptions {
        javaMaxHeapSize "2g"
    }
}

Played with these settings aswell, no success:

enter image description here

like image 384
Jim Clermonts Avatar asked May 30 '16 18:05

Jim Clermonts


People also ask

How do you pass JVM arguments in Gradle?

Try to use ./gradlew -Dorg. gradle. jvmargs=-Xmx16g wrapper , pay attention on -D , this marks the property to be passed to gradle and jvm. Using -P a property is passed as gradle project property.

Does Gradle 7 require Java 11?

Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8. You can try some of the following options: - changing the IDE settings.

What are the JVM arguments used by Gradle?

org.gradle.jvmargs=(JVM arguments) Specifies the JVM arguments used for the Gradle Daemon. The setting is particularly useful for configuring JVM memory settingsfor build performance. This does not affect the JVM settings for the Gradle client VM. The default is -Xmx512m "-XX:MaxMetaspaceSize=256m".

How do I run a Gradle project in Android Studio?

Open your project in Android Studio and select File > Settings... > Build, Execution, Deployment > Build Tools > Gradle (Android Studio > Preferences... > Build, Execution, Deployment > Build Tools > Gradle on a Mac). Under Gradle JDK, choose the Embedded JDK option. Click OK.

What is the default Java_home for Gradle?

Specifies the Java home for the Gradle build process. The value can be set to either a jdk or jre location, however, depending on what your build does, using a JDK is safer. A reasonable default is derived from your environment ( JAVA_HOME or the path to java) if the setting is unspecified.

What is the difference between Gradle build and Gradle settings?

In contrast to the build.gradle file, only one settings.gradle file is executed per Gradle build. We can use it to define the projects of a multi-project build. Besides, we can also possible to register code as part of different life cycle hooks of a build.


3 Answers

Try to add the 'org.gradle.daemon=true' inside gradle.properties file at

/Users/<username>/.gradle/ (Mac)

C:\Users\<username>\.gradle (Windows)

Answer based from

https://stackoverflow.com/a/33184794/1915831

https://stackoverflow.com/a/19500539/1915831

like image 130
Rubin Yoo Avatar answered Oct 23 '22 07:10

Rubin Yoo


This works for me :

properties file :

 org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

build file :

android {
      ...

      defaultConfig {
          ...
          multiDexEnabled true
      }


     dexOptions {
         preDexLibraries = false;
     }
}
like image 39
Merve Sahin Avatar answered Oct 23 '22 08:10

Merve Sahin


I faced this issue as well. Did not find a good answer. It is "nice" that you can fix it in your local properties folder. But people who suggest that must work on teams on 1, or want to spend time doing this fix to everyone. My group has a build server and that is the choke point.

I confirmed that Gradle is actually reading these items and that the "not used" you are reading is an error. I confirmed this by changing one of the poperties like so

org.gradle.jvmargs=-Xmx48m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

At which point I got an error. If it was not using this resource then it would not have errored with the following

Error:Execution failed for task ':app:mergeDebugResources'.
GC overhead limit exceeded
like image 3
StarWind0 Avatar answered Oct 23 '22 09:10

StarWind0