androidR 低内存编译8g “java.lang.OutOfMemoryError: Java heap space“

1.aosp11 更多的采用ninja进行编译,
更改swap分区之后,仍然报oom。

修改build/soong/java/config/config.go
pctx.StaticVariable(“JavacHeapSize”, “2048M”)
-> pctx.StaticVariable(“JavacHeapSize”, “1024M”)

修改build/soong/java/config/makevars.go
ctx.Strict(“DX_COMMAND”, “ D 8 C m d − J X m s 16 M − J X m x 2048 M " ) − > c t x . S t r i c t ( " D X C O M M A N D " , " {D8Cmd} -JXms16M -JXmx2048M") -> ctx.Strict("DX_COMMAND", " D8CmdJXms16MJXmx2048M")>ctx.Strict("DXCOMMAND","{D8Cmd} -JXms16M -JXmx1024M”)

修改 build/soong/java/droiddoc.go
在增加Flag("-J-Xmx3112m").设置metalava的堆大小
就是我们经常过不了的这条frameworks/base/api-stubs-docs-non-updatable

cmd.BuiltTool(ctx, "metalava").
 		Flag(config.JavacVmFlags).
+		Flag("-J-Xmx3112m").
 		FlagWithArg("-encoding ", "UTF-8").
 		FlagWithArg("-source ", javaVersion.String()).

实测,只需要修改build/soong/java/droiddoc.go一处便可以

android@C3478:~/project/aosp-11-2/build/soong$ git status -v
位于分支 dev
要提交的变更:
  (使用 "git restore --staged <文件>..." 以取消暂存)
	修改:     java/droiddoc.go

diff --git a/java/droiddoc.go b/java/droiddoc.go
index b564fea01..cdaf8a6cc 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -1474,6 +1474,7 @@ func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersi
 
 	cmd.BuiltTool(ctx, "metalava").
 		Flag(config.JavacVmFlags).
+		Flag("-J-Xmx3112m").
 		FlagWithArg("-encoding ", "UTF-8").
 		FlagWithArg("-source ", javaVersion.String()).
 		FlagWithRspFileInputList("@", srcs).

最后附上编译成功图
androidR 低内存编译8g “java.lang.OutOfMemoryError: Java heap space“_第1张图片

参考:https://forum.xda-developers.com/t/guide-how-to-build-android-11-with-low-ram.4298483/

你可能感兴趣的:(android,android)