ubuntu 18.04编译android 源码及问题排错

Posted 蚁人日记

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ubuntu 18.04编译android 源码及问题排错相关的知识,希望对你有一定的参考价值。

完整编译配置: https://blog.csdn.net/u012932409/article/details/104144461

编译源码

1、安装 openjdk8

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-8-jdk
java -version  #检测jdk安装

2  如果电脑里面存在多个java 版本,则通过如下命令选择openjdk-8即可

sudo update-alternative --config java
sudo update-alternative --config javac

2、安装依赖库

sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib
sudo apt-get install -y git flex bison gperf build-essential libncurses5-dev:i386
sudo apt-get install tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
sudo apt-get install dpkg-dev libsdl1.2-dev libesd0-dev
sudo apt-get install git-core gnupg flex bison gperf build-essential
sudo apt-get install zip curl zlib1g-dev gcc-multilib g++-multilib
sudo apt-get install libc6-dev-i386
sudo apt-get install lib32ncurses5-dev x11proto-core-dev libx11-dev
sudo apt-get install libgl1-mesa-dev libxml2-utils xsltproc unzip m4
sudo apt-get install lib32z-dev ccache
sudo apt-get install libssl-dev

3、开始编译


/bin/bash: m4: command not found
[ 12% 12196/98404] Check module type: out/host/linux-x86/obj/STATIC_LIBRARIES/libsepol_intermediates/link_type
[ 12% 12197/98404] Export includes file:  -- out/host/linux-x86/obj/EXECUTABLES/sepolicy-analyze_intermediates/export_includes
[ 12% 12198/98404] Import includes file: out/host/linux-x86/obj/EXECUTABLES/sepolicy-analyze_intermediates/import_includes
[ 12% 12199/98404] build out/target/product/sp7731e_1h10/sp7731e-1h10-native.dtb
[ 12% 12200/98404] Notice file: system/sepolicy/NOTICE -- out/target/product/sp7731e_1h10/obj/NOTICE_FILES/src/recovery/root/sepolicy.txt
[ 12% 12201/98404] target StaticLib: libsprd_updater (out/target/product/sp7731e_1h10/obj/STATIC_LIBRARIES/libsprd_updater_intermediates/libsprd_updater.a)
[ 12% 12202/98404] Copy: out/target/product/sp7731e_1h10/kernel
ninja: build stopped: subcommand failed.
FAILED: [W][2020-11-11T18:19:35+0800][2358] void cmdline::logParams(nsjconf_t *)():250 Process will be UID/EUID=0 in the global user namespace, and will have user root-level access to files
[W][2020-11-11T18:19:35+0800][2358] void cmdline::logParams(nsjconf_t *)():260 Process will be GID/EGID=0 in the global user namespace, and will have group root-level access to files
18:19:47 ninja failed with: exit status 1

 

遇见这个最后的报错的时候,注意向上看看base输出。
这就是问题所在,比如我的:/bin/bash: m4: command not found
然后  下载这个指令就可以了:sudo apt-get install m4
然后重新make,继续执行就可以了。


(3)FAILED: out/target/product/fugu/obj/STATIC_LIBRARIES/libedify_intermediates/lexer.cpp
/bin/bash -c "prebuilts/misc/linux-x86/flex/flex-2.5.39 -oout/target/product/fugu/obj/STATIC_LIBRARIES/libedify_intermediates/lexer.cpp bootable/recovery/edify/lexer.ll"
flex-2.5.39: loadlocale.c:130:_nl_intern_locale_data: ?? 'cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' ???
Aborted (core dumped)
[  6% 3452/56388] //frameworks/base/libs/androidfw:libandroidfw clang++ ResourceTypes.cpp [linux]
ninja: build stopped: subcommand failed.
09:56:41 ninja failed with: exit status 1

去除所有本地化的设置,让命令能正确执行,bash 执行:

export LC_ALL=C

export LC_ALL=C
to your .bashrc file under your home folder


4)error: ro.build.fingerprint cannot exceed 91 bytes
更改 build/tools/post_process_props.py 文件行 PROP_VALUE_MAX = 91 为 PROP_VALUE_MAX = 128

    #### PROP_VALUE_MAX = 91
    PROP_VALUE_MAX = 128
更改 bionic/libc/include/sys/system_properties.h 文件行 #define PROP_VALUE_MAX  91 为 #define PROP_VALUE_MAX  128
    #### #define PROP_VALUE_MAX  91
    #define PROP_VALUE_MAX  128
更改 frameworks/native/cmds/installd/installd_deps.h 文件行 constexpr size_t kPropertyValueMax = 91u; 为 constexpr size_t kPropertyValueMax = 128u;
    #### constexpr size_t kPropertyValueMax = 91u;
    constexpr size_t kPropertyValueMax = 128u;


问题一:出现*****prebuilts/misc/linux-x86/bison/bison.......

解决方法:sudo apt-get install bison

5

异常信息【5.1】14:04:54 ninja failed with: exit status 137

异常信息【5.2】

rm -rf "out/soong/.intermediates/frameworks/base/test-mock/android.test.mock.docs/android_common/srcjars"
Killed
[ 97% 86969/89259] //frameworks/base:framework javac2
[ 97% 86970/89259] //system/apex/apexd/sysprop:com.android.sysprop.apex.docs.test Metalava Check API
[ 97% 86971/89259] //system/apex/apexd/sysprop:com.android.sysprop.apex.docs.system Metalava Check API
[ 97% 86972/89259] //frameworks/base/packages/FusedLocation:FusedLocation r8
[ 97% 86973/89259] //frameworks/base/location/lib:com.android.location.provider.docs Metalava
[ 97% 86974/89259] //frameworks/base:framework javac0
[ 97% 86975/89259] //frameworks/base:framework javac1
[ 97% 86976/89259] //frameworks/base/location/lib:com.android.location.provider.docs.test Metalava
[ 97% 86977/89259] //frameworks/base/location/lib:com.android.location.provider.docs.system Metalava
[ 97% 86978/89259] //frameworks/base:framework javac3
[ 97% 86979/89259] //frameworks/base:framework javac4
[ 97% 86980/89259] //frameworks/base:framework javac5
[ 97% 86981/89259] //frameworks/base:framework javac6
[ 97% 86982/89259] //frameworks/base:framework javac7
[ 97% 86983/89259] //frameworks/base/media/lib/signer:com.android.mediadrm.signer.docs.test Metalava
[ 97% 86984/89259] //frameworks/base/media/lib/signer:com.android.mediadrm.signer.docs Metalava
[ 97% 86985/89259] //frameworks/base/media/lib/signer:com.android.mediadrm.signer.docs.system Metalava
[ 97% 86986/89259] //frameworks/base/test-mock:android.test.mock.docs.test Metalava
[ 97% 86987/89259] //frameworks/base/test-mock:android.test.mock.docs.system Metalava
ninja: build stopped: subcommand failed.
22:20:55 ninja failed with: exit status 1

此问题是因为asop/build/soong/java/config/config.go文件内定义了pctx.StaticVariable("JavacHeapSize", "2048M"),javaheap的大小与ubuntu18系统的内存调度问题有关联,javacheap的值太小会被系统直接killed掉,

所以我们修改一下javaheap的值,在编译前执行:export MAVEN_OPTS="-Xms5120m -Xmx5120m"   //配置为内存值的差不多一半吧,这个你可以自己根据你的实际来配置具体大小,

修改此片后,记得清空out目录再编译,且是必须清空 :rm -rf out

编译后要查看配置是否有生效,可以查看此文件:out/soong/build.ninja  ,在此文件内搜索JavacHeapSize,看此值是否为你设置的值,

此问题我弄了一个星期才解决,

编译前执行:  export MAVEN_OPTS=”-Xmx4800m” #maven  也可以通过设置环境变量解决该问题, 如,编辑文件 /etc/profile 如下
export M2_HOME=/usr/local/maven
export JAVA_HOME=/usr/java/jdk1.8.0_131
export PATH=$JAVA_HOME/bin:/usr/local/nginx/sbin:$PATH:$M2_HOME/bin

export MAVEN_OPTS="-Xms256m -Xmx1024m"     //必须有双引号

export MAVEN_OPTS="-Xms256m -Xmx512m"

编译Android 10时遇到关于metalava的错误。
我只在编译时使用1个线程,“ make -j1 ”。
我的计算机具有8G RAM和24G交换空间。
我注意到JVM在运行metalava时将内存限制为2GB。
这是日志
屏幕截图

您可以尝试在build / soong / java /config/ config.go中编辑以下行:
https://github.com/LineageOS/android_build_soong/blob/298e759aeb2be873488c46801c88380c5cf080e4/java/config/config.go#L54

pctx.StaticVariable("JavacHeapSize", "2048M")
pctx.StaticVariable("JavacHeapFlags", "-J-Xmx$JavacHeapSize")
pctx.StaticVariable("DexFlags", "-JXX:OnError='cat hs_err_pid%p.log' -JXX:CICompilerCount=6 -JXX:+UseDynamicNumberO

6

15:26:47 Tried to lock out/.lock, but timed out polling every 1s until 10s . Make sure no other Soong process is using it
failed to build some targets (11 seconds) ####

解决方案:

关闭当前编译Terminal窗口,另新建一个Terminal窗口再编译即可,不需要删除out再编译


6

FAILED: [W][2020-11-12T13:15:59+0800][25793] void cmdline::logParams(nsjconf_t *)():250 Process will be UID/EUID=0 in the global user namespace, and will have user root-level access to files
[W][2020-11-12T13:15:59+0800][25793] void cmdline::logParams(nsjconf_t *)():260 Process will be GID/EGID=0 in the global user namespace, and will have group root-level access to files

此问题是因为你当前是用的root用户在登录编译,退出使用其它帐号编译android,不能使用root帐号编译


下面的问题都是网络上提供解决方案,只想说android从9.0版本后就没有提供 jack-admin,他们这些解决方案都是进入prebuilts/sdk/tools/jack-admin文件修,请问他们都是怎么做的???

请别简单复制粘贴


问题二:出现ninja: build stopped: subcommand failed Android 或者GC overhead limit exceeded.
解决方法:修改prebuilts/sdk/tools/jack-admin 文件内容将
JACK_SERVER_COMMAND="java -XX:MaxJavaStackTraceDepth=-1 -Djava.io.tmpdir=$TMPDIR $JACK_SERVER_VM_ARGUMENTS -cp $LAUNCHER_JAR $LAUNCHER_NAME"
改为
JACK_SERVER_COMMAND="java -XX:MaxJavaStackTraceDepth=-1 -Djava.io.tmpdir=$TMPDIR $JACK_SERVER_VM_ARGUMENTS -Xmx4096m -cp $LAUNCHER_JAR $LAUNCHER_NAME"

依次修改下面两变量

1)、修改prebuilts/sdk/tools/jack-admin 文件,变量JACK_SERVER_VM_ARGUMENTS,添加参数 -Xmx4096M
JACK_SERVER_VM_ARGUMENTS=”$JACK_SERVER_VM_ARGUMENTS:=-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096”

2)、修改prebuilts/sdk/tools/jack-admin 文件,在 JACK_SERVER_COMMAND=“…… -cp ……” -cp 前添加-Xmx4096m(4096m为内存大小的一半左右,根据所用的主机配置而定)

JACK_SERVER_COMMAND="java -XX:MaxJavaStackTraceDepth=-1 -Djava.io.tmpdir=$TMPDIR $JACK_SERVER_VM_ARGUMENTS -Xmx4096m -cp $LAUNCHER_JAR $LAUNCHER_NAME"

注:-Xmx4096m或者-Xmx4g ,表示使用主机内存的一半,前面我说本人使用的内存是8G哦,当然如果你的内存大,可以使劲的用

./prebuilts/sdk/tools/jack-admin stop-server
./prebuilts/sdk/tools/jack-admin start-server

办法二,修改环境变量:
参考:https://blog.csdn.net/bobcat_kay/article/details/76564969?locationNum=10&fps=1,键入命令:
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

此问题三种解决方法: https://blog.csdn.net/import_sadaharu/article/details/102578624


问题三:出现Failed to contact Jack server: Problem reading .jack-server/client.pem. Try 'jack-diagnose'

  解决方法:

  jack-admin kill-server  #杀死jack进行

  jack-admin uninstall-server  #卸载jack服务

  make    # 编译

注:Jack编译器工具是一套新的Android编译工具用来将Java代码转换为Android dex字节代码,所以你jack就是用来将java代码编译成安卓的字节码编译器

 

 

 

以上是关于ubuntu 18.04编译android 源码及问题排错的主要内容,如果未能解决你的问题,请参考以下文章

[ubuntu]ubuntu18.04上源码编译protobuf

[C++][ubuntu]MNN在ubuntu18.04源码编译流程

Ubuntu18.04源码编译Carla0.9.13保姆级教程

Ubuntu18.04编译ZLMediakit支持webrtc

opencv3.4.1+ubuntu18.04+anaconda 源码编译

Android系统源码下载及编译