Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity 2017.3 fails gradle build due to java heap memory

Discussion in 'Editor & General Support' started by caletbak2, Jan 30, 2018.

  1. caletbak2

    caletbak2

    Joined:
    Oct 15, 2014
    Posts:
    13
    Since the first Unity 2017.3.0f3 and with later patch versions we can not build our project for Android anymore. It requires Gradle and the issue is:

    But the project compiles perfectly in the previous Unity 2017.2.1. I see 2 potential changes in Unity 2017.3 that could be causing the new behaviour:

    I have tried everything by now. I have created my gradle.properties file in my .gradle user folder that looks like:

    I can say Gradle is getting some of the information of this file and using it, like daemon and parallel settings, as you can see in the build log:

    BUT, I think org.gradle.jvmargs is being overriden by the gradle call that Unity is generating. If I take a look to the call to java for launching the gradle process you can see the max memory is being set with 2g:

    So as Unity is calling this process with this setting, it is impossible to me to increase the memory when gradle process starts and the project fails when Gradle comes to action. The only way I can build the game by now is exporting the project in Gradle and then use Android Studio to create the final APK. This is a big issue as many other developers would want to test some new features and would be nice to not need external tools like Android Studio to achieve it.

    So, I would expect some kind of new Gradle option in Android playersettings for setting this amount of memory Unity is sending to the command, or Unity should remove the "-Dorg.gradle.jvmargs=-Xmx2048m" from the command line for Gradle to be able to get this information from user gradle.properties.

    This problem is also happening in Unity beta 2018.1.0b4.
     
    dariony likes this.
  2. caletbak2

    caletbak2

    Joined:
    Oct 15, 2014
    Posts:
    13
    Anyone else is experimenting this issue in a big project?
     
  3. dmart331

    dmart331

    Joined:
    Jan 21, 2017
    Posts:
    2
    I'm experiencing this problem and my project isn't that large. Same issues.
     
  4. Babs_

    Babs_

    Joined:
    Jan 24, 2018
    Posts:
    1
    I'am having the same issue with "heavy" project.
     
  5. caletbak2

    caletbak2

    Joined:
    Oct 15, 2014
    Posts:
    13
  6. Lesha-VH

    Lesha-VH

    Joined:
    Jul 3, 2012
    Posts:
    96
    The same problems - project is not large

    And I suspect problems begins when I move lots of resources to Resource folder.
    Also Split Binary OGG helps to build - no errors
     
    nat-soragge likes this.
  7. elhongo

    elhongo

    Joined:
    Aug 13, 2015
    Posts:
    47
    Same problem. Had to downgrade to 2017.2 to get the APK building again.
     
  8. tarpaha

    tarpaha

    Joined:
    Jun 14, 2011
    Posts:
    4
    Same problem on 2017.4.1f1 LTS
    Same problem on 2017.3
    2017.2 contains critical issue that cause gameplay crash on Android

    The only way is use split build. This is so sad.
     
  9. jameskanestl

    jameskanestl

    Joined:
    Nov 3, 2017
    Posts:
    12
    Same issue for me. Selecting Internal Build instead of Gradle bypassed it for my work.
     
  10. ari_tendril

    ari_tendril

    Joined:
    May 14, 2018
    Posts:
    2
    You're a lifesaver! Thanks!! Internal Build worked perfectly.
     
    jameskanestl likes this.
  11. Eco-Editor

    Eco-Editor

    Joined:
    Jun 29, 2016
    Posts:
    71
    AMAZING!!!
    This worked for me too!
     
    jameskanestl likes this.
  12. SowmiyaSelva

    SowmiyaSelva

    Joined:
    Nov 14, 2017
    Posts:
    1
    Worked for me as well.
     
    jameskanestl likes this.
  13. umbrellacatgames_unity

    umbrellacatgames_unity

    Joined:
    Jul 9, 2018
    Posts:
    1
    THANKS FRIEND IT WORKS!!
     
  14. andrexrojas

    andrexrojas

    Joined:
    Apr 4, 2017
    Posts:
    1
    In "Build system" I used "Internal" and the problem desappeared
     
  15. dariony

    dariony

    Joined:
    May 16, 2015
    Posts:
    19
    Until you get to zipalign crashing if your apk is too large, if only we could disable zipalign from Unity's internal build to bypass it.
     
  16. chao3

    chao3

    Joined:
    Sep 1, 2014
    Posts:
    11
    You can export build as Gradle project and build apk with Java heap parameter

    For debug build
    java -classpath <Path to Gradle launcher> org.gradle.launcher.GradleMain -p <Path to Exported Gradle project> "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleDebug"

    For release build
    java -classpath <Path to Gradle launcher> org.gradle.launcher.GradleMain -p <Path to Exported Gradle project> "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"

    Gradle launcher could be found at:
    <Unity Install Path>\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-<version>.jar

    Built apk will output to
    <Path to Exported Gradle project>\build\outputs\apk\debug\
    <Path to Exported Gradle project>\build\outputs\apk\release\
    If you build with obb, the obb file will be exported at Gardle project root
     
    jsmouret likes this.
  17. caletbak2

    caletbak2

    Joined:
    Oct 15, 2014
    Posts:
    13
    This has been finally fixed in Unity 2017.4.13f1 LTS. Making build again from Unity without any problem.

    Changelog to check in other Unity versions:
    - Android: Increased JVM heap size from 2gb to 4gb. (969563)
     
    chao3 likes this.
  18. Shahab-Mirza

    Shahab-Mirza

    Joined:
    Aug 23, 2016
    Posts:
    8
    I had the same problem in unity 2018.4
     
  19. paulatwarp

    paulatwarp

    Joined:
    May 17, 2018
    Posts:
    135
    I'm having this problem. I've tried exporting and running the above command. But it just spits out an error:
    Error: Could not find or load main class assembleRelease
     
  20. Paul-Sinnett

    Paul-Sinnett

    Joined:
    Nov 12, 2010
    Posts:
    21
    Nevermind. The same command works fine on another machine.
     
  21. Paul-Sinnett

    Paul-Sinnett

    Joined:
    Nov 12, 2010
    Posts:
    21
    Java: write once, run somewhere.