25

Error happens when I try to compile Android source code(Sourcecode-version: 6.0.1; RAM: 6G; host system: ubuntu 14.04),log is below:

including ./system/netd/Android.mk ...
including ./system/security/keystore-engine/Android.mk ...
including ./system/security/keystore/Android.mk ...
including ./system/security/softkeymaster/Android.mk ...
including ./system/tools/aidl/Android.mk ...
including ./system/update_engine/Android.mk ...
including ./system/vold/Android.mk ...
including ./system/weaved/Android.mk ...
including ./system/webservd/Android.mk ...
including ./tools/external/fat32lib/Android.mk ...
Starting build with ninja
ninja: Entering directory `.'
[  0% 1/21275] Ensure Jack server is installed and started
Jack server already installed in "/home/eddy/.jack-server"
Launching Jack server java -Djava.io.tmpdir=/tmp -Dfile.encoding=UTF-8 -XX:+TieredCompilation -cp /home/eddy/.jack-server/launcher.jar com.android.jack.launcher.ServerLauncher
[  0% 17/21275] host Java: conscrypt-host (out/host/common/obj/JAVA_LIBRARIES/conscrypt-host_intermediates/classes)
warning: [options] bootstrap class path not set in conjunction with -source 1.7
external/conscrypt/src/openjdk/java/org/conscrypt/Platform.java:39: warning: AlgorithmId is internal proprietary API and may be removed in a future release
import sun.security.x509.AlgorithmId;
                        ^
external/conscrypt/src/openjdk/java/org/conscrypt/Platform.java:243: warning: AlgorithmId is internal proprietary API and may be removed in a future release
            return AlgorithmId.get(oid).getName();
                   ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 warnings
[  0% 18/21275] host Java: signapk (out/host/common/obj/JAVA_LIBRARIES/signapk_intermediates/classes)
warning: [options] bootstrap class path not set in conjunction with -source 1.7
1 warning
[  0% 73/21275] Building with Jack: out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/with-local/classes.dex
FAILED: /bin/bash out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/with-local/classes.dex.rsp
GC overhead limit exceeded
Try increasing heap size with java option '-Xmx<size>'
Warning: This may have produced partial or corrupted output.
ninja: build stopped: subcommand failed.
make: *** [ninja_wrapper] Error 1

#### make failed to build some targets (14:09 (mm:ss)) ####

eddy@eddy-OptiPlex-390:~/WORKING_DIRECTORY$ 

Anyone can tell me why the compiling failed?

SitiSchu
  • 1,361
  • 11
  • 20
Eddy.Liu
  • 253
  • 1
  • 3
  • 6
  • Try to see this. http://stackoverflow.com/questions/34561925/gc-overhead-limit-exceeded-when-building-android-source – Qiming Chen Mar 13 '16 at 05:25
  • Try this solution, [http://stackoverflow.com/questions/34940793/increasing-heap-size-while-building-the-android-source-code-on-ubuntu-15-10](http://stackoverflow.com/questions/34940793/increasing-heap-size-while-building-the-android-source-code-on-ubuntu-15-10) – Jacob Abraham Jul 25 '16 at 10:22

6 Answers6

53

I had the same problem. So I've tried to set JACK_SERVER_VM_ARGUMENTS to include -Xmx=4g, but when building again the log output showed that this was not included in the startup. I don't know why, it seems like the env vars do not get passed to the build script correctly.

Solution

Before starting a clean android build set the JACK_SERVER_VM_ARGUMENTS to include -Xmx=4g, then stop and start the jack server manually. Given you're in the main source tree of AOSP run the following:

export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4g"
./prebuilts/sdk/tools/jack-admin kill-server
./prebuilts/sdk/tools/jack-admin start-server

for cm you can use

export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4g"
jack-admin kill-server && jack-admin start-server

This resolved the issue for me.

peterh
  • 11,875
  • 18
  • 85
  • 108
icyerasor
  • 4,973
  • 1
  • 43
  • 52
  • I success with this modification~ – Eddy.Liu Jun 08 '16 at 09:43
  • After first run, when Jack will be unpacked, you can add JACK_SERVER_VM_ARGUMENTS to ~/.jack-settings This way it will be added automatically in future, and manual restart won't be needed. – Torbins Nov 16 '16 at 19:20
  • 1
    Normally there should be no need to specify the full path to `jack-admin`, it should be on the `$PATH` after doing `. build/envsetup.sh`. To find out if and where `jack-admin` can be found, run `which jack-admin`. – ack Jun 26 '17 at 15:02
  • This worked for me; thanks. What exactly *is* jack? It's caused me no end of problems. – Edward Falk Mar 29 '19 at 22:28
9

The current way to set Xmx for jack is:

export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096m"
out/host/linux-x86/bin/jack-admin kill-server
out/host/linux-x86/bin/jack-admin start-server
jherran
  • 3,337
  • 8
  • 37
  • 54
user6310924
  • 91
  • 1
  • 1
  • 1
    Yes. According to the jack-admin script the JACK_SERVER_VM_ARGUMENTS should be picked up. Any idea why this isn't happening during a regular android build started by make, when not manually starting the jack server? Probably the env-vars arent properly injected!? – icyerasor May 29 '16 at 22:07
7

I also had this problem after updating to 6.0 My computer is an i7 laptop with 8GB of ram. It worked fine with v5.x and below.

The reason is not enough memory as the error message states. In the v6.x build, more Jack is used. In my case, reducing the number of Jacks to 1 resolved the issue.

I can now continue compiling with 8GB of ram.

$HOME/.jack-server/config.properties
    jack.server.max-service=1

[100% 19740/19740]
#### make completed successfully (11:55:27 (hh:mm:ss)) ####
Robert
  • 10,403
  • 14
  • 67
  • 117
dave
  • 71
  • 2
  • 1
    Sorry flagged by mistake – Gyapti Jain Apr 20 '16 at 13:18
  • See my very-similar answer above that takes your solution and applies it dynamically based on the current available RAM and inserts the max number of jack servers in both the old location (pre marshmallow) and the new location (nougat and above). – Reggie Mar 28 '17 at 15:48
2

Android build (tested with 7.1.2) uses its own, private version of Jack (there could be a Jack toolchain installed elsewhere on the system), so you have to use Android-specific variables.

From https://android.googlesource.com/platform/prebuilts/sdk/+/master/tools/README-jack-server.md:

(search for "If you experience Jack compilations failing on Out of memory error.:")

To summarize:

$ # Stop the Jack server
$ jack-admin stop-server
$ # apply the new setting
$ export ANDROID_JACK_VM_ARGS="-Xmx2g -Dfile.encoding=UTF-8 -XX:+TieredCompilation"
$ Finally, restart the build (do not manually start the Jack server!)
$ m # or any other build command

The build system should pick up the change and output the line:

Environment variable ANDROID_JACK_VM_ARGS was set, regenerating...

or (after a subsequent change):

Environment variable ANDROID_JACK_VM_ARGS was modified (-Xmx2g -Dfile.encoding=UTF-8 -XX:+TieredCompilation => -Xmx4g -Dfile.encoding=UTF-8 -XX:+TieredCompilation), regenerating...
ack
  • 7,356
  • 2
  • 25
  • 20
  • +1 yes, I too was building 7.1.2 and this answer worked best for my scenario. The other answers were informative and helpful, but this one fixed the problem. – Les Nov 17 '17 at 14:38
1

I found this article: Building AOSP 7.x Nougat with only 8 GiB RAM


on an 8 GiB machine, Max Heap size is less than 2 GiB:

$ java -XshowSettings 2>&1  | grep Heap
    Max. Heap Size (Estimated): 1.71G

The solution

Once I understood the problem, it was just a question of changing the default heap size when jack-server is launched. To fix it, you need to edit ~/.jack-settings, and add this line

JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096m"

Then, restart jack-server – otherwise if it is running in the background it will continue to use the old Xmx value:

$ prebuilts/sdk/tools/jack-admin kill-server
$ prebuilts/sdk/tools/jack-admin start-server
Launching Jack server java -XX:MaxJavaStackTraceDepth=-1 -Djava.io.tmpdir=/tmp -Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096m
-cp /home/chris/.jack-server/launcher.jar com.android.jack.launcher.ServerLauncher
Corey
  • 1,217
  • 3
  • 22
  • 39
Kamin
  • 11
  • 2
0

This was also my problem: the java default Xmx setting was already close to 4GB (precisely: 4011MB) so the issue was rather the number of concurrent jack servers running. My machine had 8 CPUs but only 16GB of RAM, but would have required 32GB (8*4=32).

My (slightly more dynamic) solution:

MAX=$(($(free -g | awk '/^Mem:/{print $NF}') / 4))
if [ $MAX -le 0 ]; then
    MAX=1
fi
echo "SERVER_NB_COMPILE=$MAX" >> ~/.jack
mkdir -p ~/.jack-server
echo "jack.server.max-service=$MAX" >> ~/.jack-server/config.properties

It adds the MAX number of jack server to both the old-location and new-location based on the android official doc:

Jack Troubleshooting: If your computer becomes unresponsive during compilation or if you experience Jack compilations failing on “Out of memory error”, you can improve the situation by reducing the number of Jack simultaneous compilations by editing your $HOME/.jack and changing SERVER_NB_COMPILE to a lower value. https://source.android.com/source/jack.html

Reggie
  • 644
  • 5
  • 10