Java 在 Ubuntu 15.10 上构建 android 源代码时增加堆大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34940793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 16:08:58  来源:igfitidea点击:

Increasing heap size while building the android source code on Ubuntu 15.10

javaandroidubuntu

提问by Smile Wei

I am trying to build the android source code in ubuntu 15.10, but I got an error. Now I want your help to build the android source code.

我正在尝试在 ubuntu 15.10 中构建 android 源代码,但出现错误。现在我需要你的帮助来构建 android 源代码。

including ./tools/external/fat32lib/Android.mk ...
Starting build with ninja
ninja: Entering directory `.'
[  0% 1/21542] Ensure Hyman server is installed and started
Hyman server already installed in "/home/smile/.Hyman-server"
Server is already running
[  0% 2/21542] Building with Hyman: out/target/common/obj/JAVA_LIBRARIES/core-all_intermediates/with-local/classes.dex
FAILED: /bin/bash out/target/common/obj/JAVA_LIBRARIES/core-all_intermediates/with-local/classes.dex.rsp
Java heap space
Try increasing heap size with java option '-Xmx<size>'
Warning: This may have produced partial or corrupted output.
ninja: build stopped: subcommand failed.
build/core/ninja.mk:146: recipe for target 'ninja_wrapper' failed
make: *** [ninja_wrapper] Error 1

#### make failed to build some targets (08:25 (mm:ss)) ####

Then I run "$ java -Xmx2048m" command and I get some lines:

然后我运行“$ java -Xmx2048m”命令,我得到一些行:

 smile@smile:~/Android$ java -Xmx2048m
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)
where options include:
    -d32      use a 32-bit data model if available
    -d64      use a 64-bit data model if available
    -server   to select the "server" VM
    -zero     to select the "zero" VM
    -jamvm    to select the "jamvm" VM
    -avian    to select the "avian" VM
    -dcevm    to select the "dcevm" VM
                  The default VM is server.

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A : separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D<name>=<value>
                  set a system property
    -verbose:[class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:<value>
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -no-jre-restrict-search
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions with specified granularity
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions with specified granularity
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:<libname>[=<options>]
                  load native agent library <libname>, e.g. -agentlib:hprof
                  see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
                  load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
                  load Java programming language agent, see java.lang.instrument
    -splash:<imagepath>
                  show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.

Who can help me how to increase heap size?

谁能帮助我如何增加堆大小?

Your help will be greatly appretiated to me

你的帮助将极大地感谢我

Thanks in advance.

提前致谢。

smile@smile:~/Android$ java -version
java version "1.7.0_91"
OpenJDK Runtime Environment (IcedTea 2.6.3) (7u91-2.6.3-0ubuntu0.15.10.1)
OpenJDK 64-Bit Server VM (build 24.91-b01, mixed mode)

回答by Milo? Ratkovi?

I've just run into same problem.

我刚刚遇到了同样的问题。

The problem is that virtual machine which runs Hyman doesn't have enough memory.

问题是运行 Hyman 的虚拟机没有足够的内存。

You can try to edit jvm command:

您可以尝试编辑 jvm 命令:

Hyman_VM_COMMAND=${Hyman_VM_COMMAND:="java -Xmx4096m"}

or to decrease number of parallel Hyman compilations

或减少并行插孔编辑的数量

SERVER_NB_COMPILE=2

in ~/.Hymanfile.

~/.Hyman文件中。

You can read Hyman documentationfor details.

您可以阅读Hyman 文档了解详细信息。

EDIT: Changing .Hyman file didn't work for me. After digging a little deeper I found that Hyman server is started with out/host/linux-x86/bin/Hyman-admin script and it's parameters can be passed with Hyman_SERVER_VM_ARGUMENTS environment variable.

编辑:更改 .Hyman 文件对我不起作用。深入挖掘后,我发现 Hyman 服务器是用 out/host/linux-x86/bin/Hyman-admin 脚本启动的,它的参数可以通过 Hyman_SERVER_VM_ARGUMENTS 环境变量传递。

So my solution was to set it and restart Hyman server before building aosp :

所以我的解决方案是在构建 aosp 之前设置它并重新启动 Hyman 服务器:

export Hyman_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096m"
out/host/linux-x86/bin/Hyman-admin kill-server
out/host/linux-x86/bin/Hyman-admin start-server

回答by Suraj

If you are building Android N then Hyman config files is changed. apply above suggested configs by following Transition Guide.

如果您正在构建 Android N,则 Hyman 配置文件会更改。按照转换指南应用以上建议的配置。

find the config you want to change, find where it moved from $HOME/.Hymanand change it there.

找到您要更改的配置,找到它从哪里移动$HOME/.Hyman并在那里进行更改。

Transitioning from server 1.1 (e.g. Marshmallow) to server 1.3 (e.g. N)

从服务器 1.1(例如 Marshmallow)过渡到服务器 1.3(例如 N)

The old Hyman server used a $HOME/.Hymanconfiguration file. It has now replaced by a $HOME/.Hyman-settingsand a $HOME/.Hyman-server/config.properties.

旧的 Hyman 服务器使用了一个$HOME/.Hyman配置文件。它现在已替换为 a$HOME/.Hyman-settings和 a $HOME/.Hyman-server/config.properties

If those new files do not exist,

如果这些新文件不存在,

run Hyman-admin start-serverand they will be created.

运行Hyman-admin start-server,它们将被创建。

If you had custom settings in your $HOME/.Hyman, here's how to adapt those.

如果您的 中有自定义设置,以下$HOME/.Hyman是调整这些设置的方法。

Step 1

第1步

SERVER_PORT_SERVICE=XXXXReplace with SERVER_PORT_SERVICE=XXXXin $HOME/.Hyman-settingsand Hyman.server.service.port=XXXXin $HOME/.Hyman-server/config.properties.

SERVER_PORT_SERVICE=XXXX替换为SERVER_PORT_SERVICE=XXXXin $HOME/.Hyman-settingsHyman.server.service.port=XXXXin $HOME/.Hyman-server/config.properties

Step 2

第2步

SERVER_PORT_ADMIN=YYYYReplace with SERVER_PORT_ADMIN=YYYYin $HOME/.Hyman-settingsand Hyman.server.admin.port=YYYYin $HOME/.Hyman-server/config.properties.

SERVER_PORT_ADMIN=YYYY替换为SERVER_PORT_ADMIN=YYYYin $HOME/.Hyman-settingsHyman.server.admin.port=YYYYin $HOME/.Hyman-server/config.properties

Step 3

第 3 步

SERVER_NB_COMPILE=NReplace with Hyman.server.max-service=Nin $HOME/.Hyman-server/config.properties.

SERVER_NB_COMPILE=N替换为Hyman.server.max-service=Nin $HOME/.Hyman-server/config.properties

Extra Settings

额外设置

SERVER_TIMEOUT=ZZYou can replace with Hyman.server.time-out=ZZ, but it is recommended to keep the default setting of “7200” (2 hours).

Other settings in the $HOME/.Hymanconfiguration file do not need to be copied. You should still keep your $HOME/.Hymanconfiguration file for the old Hyman server because both server versions can run simultaneously.

SERVER_TIMEOUT=ZZ可以替换为Hyman.server.time-out=ZZ,但建议保留默认设置“7200”(2 小时)。

$HOME/.Hyman配置文件中的其他设置不需要复制。您仍然应该保留$HOME/.Hyman旧 Hyman 服务器的配置文件,因为两个服务器版本可以同时运行。

Taken from Hyman server, more on Compiling with Hyman

取自Hyman 服务器,更多关于使用 Hyman 编译

回答by Layne Zhang

Hyman_server_setup.mk under prebuilts\sdk\tools

Hyman_server_setup.mk 在 prebuilts\sdk\tools 下

ifneq ($(ANDROID_Hyman_VM_ARGS),)
Hyman_vm_args := $(ANDROID_Hyman_VM_ARGS)
else
Hyman_vm_args := -Dfile.encoding=UTF-8 -XX:+TieredCompilation
endif
.....
ifneq ($(dist_goal),)
    $(hide) mkdir -p "$(DIST_DIR)/logs/Hyman/"
    $(hide) Hyman_SERVER_VM_ARGUMENTS="$(Hyman_vm_args) -Dcom.android.Hyman.server.log.file=$(abspath $(DIST_DIR))/logs/Hyman/Hyman-server-%u-%g.log" $(PRIVATE_Hyman_ADMIN) start-server 2>&1 || exit 0
else
    $(hide) Hyman_SERVER_VM_ARGUMENTS="$(Hyman_vm_args)" $(PRIVATE_Hyman_ADMIN) start-server 2>&1 || exit 0
endif

So we can export

所以我们可以导出

ANDROID_Hyman_VM_ARGS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4g"

to config Hyman args. And then run this below:

配置插孔参数。然后在下面运行:

./prebuilts/sdk/tools/Hyman-admin kill-server
./prebuilts/sdk/tools/Hyman-admin start-server

回答by Vignesh Prasad V

goto build/core/config.mk and change heap size in

转到 build/core/config.mk 并更改堆大小

APICHECK_COMMAND := $(APICHECK) -JXmx8g-J"classpath $(APICHECK_CLASSPATH)"

APICHECK_COMMAND := $(APICHECK) -JXmx8g-J"classpath $(APICHECK_CLASSPATH)"

then it will work fine.
Other solutions didn't help me.

然后它会正常工作。
其他解决方案对我没有帮助。

回答by lubik1

Just try add

试试添加

export ANDROID_Hyman_VM_ARGS="-Xmx8192m -Xms512m -Dfile.encoding=UTF-8 -XX:+TieredCompilation"

to the end of .bashrcand reboot Linux

.bashrc的末尾并重新启动 Linux