Android source code compile error: "Try increasing heap size with java option '-Xmx<size>'"
Android source code compile error: "Try increasing heap size with java option '-Xmx<size>'"
编译Android源代码时出现错误(Sourcecode-version: 6.0.1; RAM: 6G; host system: ubuntu 14.04),日志如下:
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$
谁能告诉我编译失败的原因?
更新到 6.0 后我也遇到了这个问题我的电脑是 i7 笔记本电脑,内存为 8GB。它适用于 v5.x 及以下版本。
如错误消息所述,原因是 内存不足。在 v6.x 构建中,使用了更多的 Jack。在我的例子中,将 Jacks 的数量减少到 1 解决了这个问题。
我现在可以使用 8GB 的内存继续编译了。
$HOME/.jack-server/config.properties
jack.server.max-service=1
[100% 19740/19740]
#### make completed successfully (11:55:27 (hh:mm:ss)) ####
目前为jack设置Xmx的方式是:
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
我遇到了同样的问题。所以我尝试将 JACK_SERVER_VM_ARGUMENTS
设置为包含 -Xmx=4g
,但是当再次构建时,日志输出显示这未包含在启动中。我不知道为什么,似乎环境变量没有正确传递给构建脚本。
解决方案
在开始干净的 android 构建之前,将 JACK_SERVER_VM_ARGUMENTS
设置为包含 -Xmx=4g
,然后停止并 手动 启动 jack 服务器。假设您位于 AOSP 运行 的主要源代码树中,则如下:
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
对于cm你可以使用
export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4g"
jack-admin kill-server && jack-admin start-server
这解决了我的问题。
这也是我的问题:java 默认 Xmx 设置已经接近 4GB(准确地说:4011MB)所以问题是并发服务器的数量 运行。我的机器有 8 个 CPU 但只有 16GB 的内存,但需要 32GB (8*4=32)。
我的(稍微更动态的)解决方案:
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
根据android官方文档,将jack服务器的最大数量添加到旧位置和新位置:
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
Android build(用 7.1.2 测试)使用它自己的私有版本的 Jack(系统的其他地方可能安装了 Jack 工具链),所以你必须使用 Android -特定变量。
来自https://android.googlesource.com/platform/prebuilts/sdk/+/master/tools/README-jack-server.md:
(搜索 "If you experience Jack compilations failing on Out of memory error.:")
总结一下:
$ # 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
构建系统应该获取更改并输出行:
Environment variable ANDROID_JACK_VM_ARGS was set, regenerating...
或(在后续更改后):
Environment variable ANDROID_JACK_VM_ARGS was modified (-Xmx2g -Dfile.encoding=UTF-8 -XX:+TieredCompilation => -Xmx4g -Dfile.encoding=UTF-8 -XX:+TieredCompilation), regenerating...
我找到这篇文章:
Building AOSP 7.x Nougat with only 8 GiB RAM
在 8 GiB 机器上,最大堆大小小于 2 GiB:
$ java -XshowSettings 2>&1 | grep Heap
Max. Heap Size (Estimated): 1.71G
解决方法
一旦我理解了这个问题,这只是在启动 jack-server 时更改默认堆大小的问题。要修复它,您需要编辑
~/.jack-settings
,并添加这一行
JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096m"
然后,重新启动 jack-server – 否则如果它在后台 运行 它将继续使用旧的 Xmx 值:
$ 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
编译Android源代码时出现错误(Sourcecode-version: 6.0.1; RAM: 6G; host system: ubuntu 14.04),日志如下:
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$
谁能告诉我编译失败的原因?
更新到 6.0 后我也遇到了这个问题我的电脑是 i7 笔记本电脑,内存为 8GB。它适用于 v5.x 及以下版本。
如错误消息所述,原因是 内存不足。在 v6.x 构建中,使用了更多的 Jack。在我的例子中,将 Jacks 的数量减少到 1 解决了这个问题。
我现在可以使用 8GB 的内存继续编译了。
$HOME/.jack-server/config.properties
jack.server.max-service=1
[100% 19740/19740]
#### make completed successfully (11:55:27 (hh:mm:ss)) ####
目前为jack设置Xmx的方式是:
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
我遇到了同样的问题。所以我尝试将 JACK_SERVER_VM_ARGUMENTS
设置为包含 -Xmx=4g
,但是当再次构建时,日志输出显示这未包含在启动中。我不知道为什么,似乎环境变量没有正确传递给构建脚本。
解决方案
在开始干净的 android 构建之前,将 JACK_SERVER_VM_ARGUMENTS
设置为包含 -Xmx=4g
,然后停止并 手动 启动 jack 服务器。假设您位于 AOSP 运行 的主要源代码树中,则如下:
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
对于cm你可以使用
export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4g"
jack-admin kill-server && jack-admin start-server
这解决了我的问题。
这也是我的问题:java 默认 Xmx 设置已经接近 4GB(准确地说:4011MB)所以问题是并发服务器的数量 运行。我的机器有 8 个 CPU 但只有 16GB 的内存,但需要 32GB (8*4=32)。
我的(稍微更动态的)解决方案:
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
根据android官方文档,将jack服务器的最大数量添加到旧位置和新位置:
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
Android build(用 7.1.2 测试)使用它自己的私有版本的 Jack(系统的其他地方可能安装了 Jack 工具链),所以你必须使用 Android -特定变量。
来自https://android.googlesource.com/platform/prebuilts/sdk/+/master/tools/README-jack-server.md:
(搜索 "If you experience Jack compilations failing on Out of memory error.:")
总结一下:
$ # 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
构建系统应该获取更改并输出行:
Environment variable ANDROID_JACK_VM_ARGS was set, regenerating...
或(在后续更改后):
Environment variable ANDROID_JACK_VM_ARGS was modified (-Xmx2g -Dfile.encoding=UTF-8 -XX:+TieredCompilation => -Xmx4g -Dfile.encoding=UTF-8 -XX:+TieredCompilation), regenerating...
我找到这篇文章: Building AOSP 7.x Nougat with only 8 GiB RAM
在 8 GiB 机器上,最大堆大小小于 2 GiB:
$ java -XshowSettings 2>&1 | grep Heap
Max. Heap Size (Estimated): 1.71G
解决方法
一旦我理解了这个问题,这只是在启动 jack-server 时更改默认堆大小的问题。要修复它,您需要编辑
~/.jack-settings
,并添加这一行
JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096m"
然后,重新启动 jack-server – 否则如果它在后台 运行 它将继续使用旧的 Xmx 值:
$ 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