Android编译环境折腾记

 一、Ubuntu编译Android4.4.4

1.平台:realtek RTD2984(Android4.4.4)

  第一次安装了ubuntu14.04.5,官网下载的iso,官网下的jar,编译android4.x需要安装jdk6,更高的版本会有问题,baidu到很多搭建环境的步骤,这个不多说,在win7下使用EasyBCD引导安装的ubuntu,1TB硬盘果断装了双系统,事实证明没删掉win7是个多么明智的决定,在jdk方面,android4.4比4.0要多配置一个javap,其他都一样

 1 update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.6.0_43/bin/java" 1
 2 update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.6.0_43/bin/javac" 1
 3 update-alternatives --install "/usr/bin/javadoc" "javadoc" "/usr/lib/jvm/jdk1.6.0_43/bin/javadoc" 1
 4 update-alternatives --install "/usr/lib/mozilla/plugins/libjavaplugin.so" "mozilla-javaplugin.so" "/usr/lib/jvm/jdk1.6.0_43/jre/lib/amd64/libnpjp2.so" 1
 5 update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.6.0_43/bin/javaws" 1
 6 update-alternatives --install "/usr/bin/javap" "javap" "/usr/lib/jvm/jdk1.6.0_43/bin/javap" 1
 7 update-alternatives --install "/usr/bin/jar" "jar" "/usr/lib/jvm/jdk1.6.0_43/bin/jar" 1
 8 
 9 # Choose the java you installed as default 
10 update-alternatives --config java
11 update-alternatives --config javac
12 update-alternatives --config javadoc
13 update-alternatives --config mozilla-javaplugin.so
14 update-alternatives --config javaws
15 update-alternatives --config javap
16 update-alternatives --config jar

  接下来就是安装库文件了,库文件不能少,不然会报错缺少xxx中断编译,这个比较好处理,缺啥apt-get啥,但是还是在事先就全部安装好,这编译一次4.4也不容易,好几个小时呢

sudo apt-get install git git-core gnupg flex bison gperf build-essential
sudo apt-get install zip curl libc6-dev x11proto-core-dev tofrodos

sudo apt-get install libx11-dev:i386 libreadline6-dev:i386

sudo apt-get install python-markdown libxml2-utils xsltproc zlib1g-dev:i386

sudo apt-get install lib32z1 dos2unix gcc g++ g++-multilib gcc-multilib

sudo apt-get install lib32ncurses5 lib32ncurses5-dev libncurses5-dev libncursesw5-dev lib32ncursesw5-dev

  注:mingw32 libgl1-mesa-glx-lts-quantal:i386 libgl1-mesa-dev-lts-quantal 这三个包我在安装的时候无法定位,不影响使用

  并且,gcc与g++请再次安装自己需要的版本

  例如gcc4.7(编译Android4.4)

sudo apt-get install gcc-4.7 g++-4.7 g++-4.7-multilib gcc-4.7-multilib

   若出现无法定位的错误,如在Ubuntu16.04.02上安装gcc-4.4.7(编译Android4.0.3),添加源,然后再次安装gcc版本即可

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update

  但是!!由于我是编译公司已有的源码,并不是原生系统源码,报错了,第一次是有个文件没有自动生成!!一个REVISION的变量undefined,于是找到报错的文件一个一个defined,但是!!!师父的电脑能编译通过,自动生成的ver.h文件里面包含了REVISION变量的定义,这就有意思了,于是跑到到师父电脑上一查jdk,ubuntu,gcc,g++等版本,jdk有小版本的不同,但这个应该不是关键,ubuntu都是14.04的,gcc/g++都是4.8.4,也就是ubuntu14.04自带的编译器,然后还有交叉编译器,这个在源码中包含了arm-linux-gcc,版本肯定是一样的,后来碰到有大神说是gcc的版本太高了,可问题是师父的gcc也是4.8啊为什么就不报错!!!心塞塞。。。改完了这个undefined error,编译继续,然后碰到了更多的undefined。。。

  比如plural-exp.h文件中的# define PLURAL_PARSE __gettextparse报conflicting types错误

 1 In file included from ../../../binutils-gdb/intl/plural.y:35:0:
 2 ../../../binutils-gdb/intl/plural-exp.h:102:23: error: conflicting types for
 3 'libintl_gettextparse'
 4 # define PLURAL_PARSE libintl_gettextparse
 5                        ^
 6 ../../../binutils-gdb/intl/plural.y:40:25: note: in expansion of macro
 7 'PLURAL_PARSE'
 8 # define __gettextparse PLURAL_PARSE
 9                          ^
10 plural.c:185:5: note: in expansion of macro '__gettextparse'
11 int __gettextparse (void);
12      ^
13 ../../../binutils-gdb/intl/plural-exp.h:102:23: note: previous declaration
14 of 'libintl_gettextparse' was here
15 # define PLURAL_PARSE libintl_gettextparse
16                        ^
17 ../../../binutils-gdb/intl/plural-exp.h:114:12: note: in expansion of macro
18 'PLURAL_PARSE'
19 extern int PLURAL_PARSE PARAMS ((void *arg));
20             ^
21 ../../../binutils-gdb/intl/plural-exp.h:102:23: error: conflicting types for
22 'libintl_gettextparse'
23 # define PLURAL_PARSE libintl_gettextparse
24                        ^
25 ../../../binutils-gdb/intl/plural.y:40:25: note: in expansion of macro
26 'PLURAL_PARSE'
27 # define __gettextparse PLURAL_PARSE
28                          ^
29 plural.c:63:25: note: in expansion of macro '__gettextparse'
30 #define yyparse         __gettextparse
31                          ^
32 plural.c:1130:1: note: in expansion of macro 'yyparse'
33 yyparse (void)
34 ^
35 ../../../binutils-gdb/intl/plural-exp.h:102:23: note: previous declaration
36 of 'libintl_gettextparse' was here
37 # define PLURAL_PARSE libintl_gettextparse
38                        ^
39 ../../../binutils-gdb/intl/plural-exp.h:114:12: note: in expansion of macro
40 'PLURAL_PARSE'
41 extern int PLURAL_PARSE PARAMS ((void *arg));
42             ^
43 plural.c: In function 'libintl_gettextparse':
44 plural.c:1299:7: error: too few arguments to function '__gettextlex'
45        yychar = yylex (&yylval);
46        ^
47 plural.c:64:25: note: declared here
48 #define yylex           __gettextlex
49                          ^
50 ../../../binutils-gdb/intl/plural.y:69:12: note: in expansion of macro
51 'yylex'
52 static int yylex PARAMS ((YYSTYPE *lval, const char **pexp));
53             ^
54 ../../../binutils-gdb/intl/plural.y:178:29: error: 'arg' undeclared (first
55 use in this function)
56       ((struct parse_args *) arg)->res = $1;
57                              ^

  对没错,就是下面这个链接的错误!!!

http://stackoverflow.com/questions/33562051/conflicting-types-for-libintl-gettextparse

  网上碰到这个错误的还真不多,可能是我运气真的太好,网上的解决方法是bison版本过低,升级到3.0就好了,屁啊。我的bison版本就是3.0.2,师父的环境也是3.0.2,自己找了好久不了了之。。。

  于是,我默默的格式化了ubuntu系统的所在磁盘,这一删不得了,因为ubuntu与windows双系统是ubuntu在进行开机引导的,所以很正常的我开不了机了23333,没关系,我还可以进U盘的PE系统,咳咳,那个由于我是四五年前的时候给U盘做的启动盘了,又很正常的PE系统检测不到公司配的新电脑的硬盘!!这我一下子蒙圈了,网上一搜,原来是U盘PE系统太老了,还好!!我自己电脑还在旁边,于是又下个laomaotao啥的搞个最新的PE,终于能检测到硬盘啦,那然后是用U盘直接装Ubuntu呢还是继续win7引导,想想就我这运气还是继续靠win7吧,用分区工具重写了grub,这样又能正常引导开机啦

  以前在学校的时候自己有个arm9的开发版,编过android4.0的系统,编译环境还是ubuntu12.04,于是这次上官网下了个ubuntu12.04.5,烧写完毕,重启,哎呀我去又出大事了!!ubuntu开不了机了。报了个错网上一搜,说是Thinkpad的bios的设置,不兼容的问题,具体错误不太记得了,但是!我还是坚持着又烧写了一次ubuntu12.04.2,注意这次是2!!!然后神奇的是居然进到桌面了,难道是自己在配置ubuntu12.04.5的时候出了岔子??哎不管了,2与5又有多大的差别呢,又不是14.04,用了会14.04还是觉得14.04好看很多啊!!!(谁让我是个看颜值的程序猿呢

  这次用ubuntu12.04.2应该没啥问题了吧,源码download下来,环境轻车熟路的搭建好,开始编译!恩,REVISION undefined依然遇到,改过继续,这次碰到更奇葩的error了!!baidu/google都没几个人碰到的啊

  compile_et: Couldn*t find compile_et*s template files

  搜过来搜过去就只有这哥们的帖子( http://tieba.baidu.com/p/3199034286  按照回帖的做了,这库文件早就是最新的了,所以没用,没办法,只有看Makefile文件了,没有找到compile_et 的模板文件,是报错的prof_err.et还是啥??于是用命令compile_et prof_err.et 这个没报错啊,于是又编译一次,还是错了,看Makefile文件,哦!原来是compile_et --buildtree prof_err.et 这个命令,那确实,会报错,卡了好久,有次莫名其妙的vi了一下compile_et这个工具,工具???md,原来是shell脚本啊,只读的shell脚本啊,又是自动生成的shell脚本啊!没有后缀的compile_et我tm还以为是像windows里的exe工具一样呢,真是玩windows玩入魔了,这该死的定式思维,然后一个大写的绝对路径在里面躺着啊!!这路径还是师父的路径啊!!!这个文件就压根没有自动生成啊!!!这把我坑的我也不多说什么了,改掉!!!!编译终于通过了!!测试一下,没错!终于跑起来了!!开心啊,然后开开心心的回家了,第二天......

  吃完早餐,开心的打开电脑,然后,1分钟过去了..5分钟过去了...10分钟过去了......ubuntu卡在了用户登录之前!!!ubuntu死掉了!!!我去!!!为什么!!!搞了个把小时没用,各种方法试过,没用!!决定重装ubuntu,师父一脸惊呆的问我,你又准备重装啊?我:......(泪  (这个问题是由于在64位系统上安装了32位的库,而12.04安装32位兼容包有问题。(补充:在Ubuntu14.04和16.04上貌似不会)

  然后心里还是默默的挂念着ubuntu14.04,然后又装了14.04,真是做死,豪无疑问又碰到了# define PLURAL_PARSE __gettextparse报conflicting types的错误,装的太多次都忘记14.04是这个错误了2333,真是为自己捉急!!无奈,为了节省时间只好装回12.04.2...把上次碰到的错误都解决掉,这次成功进入了系统!!!

 

--------------------------------20161028------update-----------

  Ubuntu16.04.1编译这个项目的时候也碰到这个问题plural-exp.h:94:23: error: conflicting types for 'libintl_gettextparse'

 

-------------------------------20161031-------update-------------

  终于把上述问题(plural.c编译错误)解决啦!!!开心ing....

  果然是bison版本的问题,ubuntu14.04.5执行apt-get install bison得到版本是3.0.2;ubuntu16.04.1执行apt-get install bison得到版本是3.0.4

  然而bison3.0才会报这个错误!!!!!!因为今天找师父要了plural.c这个文件(注意在他电脑上编译是可以通过的,而且这个文件是自动生成的,然后第一句就是这么写着。

1 /* A Bison parser, made by GNU Bison 2.7.12-4996.  */
2 
3 /* Bison implementation for Yacc-like parsers in C
4    
5       Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.

  bison版本是2.7.1啊啊啊啊啊啊!!!于是我把自己bison版本降到了2.7.1,然后!!!然后!!!成功了!!接着就烧写,开机,启动,进入桌面,完美!!

  bison版本变更请移步:http://www.cnblogs.com/pngcui/p/6014896.html

-------------------------------end -----------------------------------

 

总结:经过这么长时间的折腾,以后在也不想再在环境这个问题上搞来搞去了。。。烦人!!系统的文件自己不知道的决不再乱动,万一就开不了机了。。。

 

这里附上一键搭建Android4.4编译环境的脚本,解压之后使用脚本

sudo ./auto_install

请务必使用root权限执行,因为压缩包里包含jdk1.6.0_43.bin文件,执行脚本会自动mv到/usr/lib/jvm/下,这里需要root权限才能执行

   传送门:http://download.csdn.net/detail/u012062785/9891147

 

 ***************************我是分割线********************************************

2.平台:Mstar648(Android4.4.4)

 --------------------------------------------------20161220 update -----------------------------------

  1.后来在编译msd6a648的时候报了如下错误

bash: ./bin/arm-none-linux-gnueabi-gcc: No such file or directory

  查环境变量的时候发现该路径存在,且该文件也存在!

  使用命令arm-none-linux-gnueabi-gcc -v 就会报如上错误,经baidu后发现是32位库兼容性问题

  可安装如下软件解决问题

sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0

  2.编译kernel make menuconfig时,报如下错误

./mpatch_gen.sh
ConfigName=mpatch.config HeaderName=mpatch_macro.h KconfigName=mpatch_Kconfig DocPath=mstar2/mpatch/doc/
Process mpatch Done...
./gen_cl.sh
fatal: Not a git repository (or any of the parent directories): .git
  HOSTLD  scripts/kconfig/mconf
/usr/bin/ld: cannot find -lncursesw
collect2: error: ld returned 1 exit status
make[1]: *** [scripts/kconfig/mconf] Error 1
make: *** [menuconfig] Error 2

  使用ln -s创建链接指向x86_64-linux-gnu/libcursesw.so 无用!!!

  可是64位ubuntu已安装了libncurses5-dev,libncursesw5-dev,lib32ncurses5-dev,突然一想,是不是还有lib32ncursesw5-dev需要安装阿?!!!!!遂安装之

sudo apt-get install lib32ncursesw5-dev

  我去,居然成了!,遂记录之,继而感叹真tm坑爹。

 

----------------------------------------------20170208----------------------------------------------------------

  编译Android报错

including ./vendor/mstar/supernova/projects/Android.mk ...
Export includes file: external/bluetooth/bluedroid/hci/Android.mk -- out/target/product/generic/obj/SHARED_LIBRARIES/libbt-hci_intermediates/export_includes
Export includes file: external/bluetooth/bluedroid/utils/Android.mk -- out/target/product/generic/obj/SHARED_LIBRARIES/libbt-utils_intermediates/export_includes
Export includes file: external/bluetooth/bluedroid/gki/Android.mk -- out/target/product/generic/obj/STATIC_LIBRARIES/libbt-brcm_gki_intermediates/export_includes
Export includes file: external/bluetooth/bluedroid/bta/Android.mk -- out/target/product/generic/obj/STATIC_LIBRARIES/libbt-brcm_bta_intermediates/export_includes
Export includes file: external/bluetooth/bluedroid/stack/Android.mk -- out/target/product/generic/obj/STATIC_LIBRARIES/libbt-brcm_stack_intermediates/export_includes
Import includes file: out/target/product/generic/obj/SHARED_LIBRARIES/bluetooth.default_intermediates/import_includes
target thumb C++: bluetooth.default <= external/bluetooth/bluedroid/main/../btif/src/btif_config_util.cpp
target thumb C: bluetooth.default <= external/bluetooth/bluedroid/main/../btif/src/bluetooth.c
external/bluetooth/bluedroid/main/../btif/src/bluetooth.c:415:1: error: missing initializer [-Werror=missing-field-initializers]
external/bluetooth/bluedroid/main/../btif/src/bluetooth.c:415:1: error: (near initialization for 'bluetoothInterface.enter_headless_mode') [-Werror=missing-field-initializers]
cc1: all warnings being treated as errors
make: *** [out/target/product/generic/obj/SHARED_LIBRARIES/bluetooth.default_intermediates/../btif/src/bluetooth.o] 错误 1

  最后找到原因的我眼泪掉下来....

  居然是因为在编译android的之前没有lunch!!!我的天,还是要细心细心

 

 二、Ubuntu16.04.1编译Android5.0.1

1.平台:Mstar828(Android5.0.1)

  Android5.x以上需要使用openjdk7,没有tar,只有deb,只有各种依赖,宝宝心里苦啊。。。折腾一上午决定从ubuntu12.04.4升级到16.04.1,这次又会碰到什么奇葩问题呢?让我们敬请期待吧,咳咳,Android5.0的编译与Android4.4的编译环境只有jdk不一样,其他是一样的,gcc采用4.7即可。

  openjdk7安装方法(由于16.04去掉了openjdk的源,所以加上即可)

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-7-jdk  

 

---------------------------------------------20160928----------------------------------------第一个error

  Uboot编译

1 /bin/sh: 1: Syntax error: Missing '))'
2 Makefile:2285: recipe for target 'out/chunk_header.bin' failed

  解决:sudo dpkg-reconfigure dash 选择no
  原因:http://www.minroad.com/?p=543

 

-------------------------------------------20160928----------------------------------------第二个

  Android 编译:

1 /home/pngcui/MSD6A828/l-828-0513/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6/bin/../lib/gcc/x86_64-linux/4.6/../../../../x86_64-linux/bin/ld: error: out/host/linux-x86/obj32/STATIC_LIBRARIES/libcompiler_rt_intermediates/libcompiler_rt.a(eprintf.o): unsupported reloc 43 against global symbol stderr
2 external/compiler-rt/lib/builtins/eprintf.c:32: error: unsupported reloc 43
3 collect2: ld returned 1 exit status
4 build/core/host_shared_library_internal.mk:44: recipe for target 'out/host/linux-x86/obj32/lib/libcompiler_rt.so' failed
5 make: *** [out/host/linux-x86/obj32/lib/libcompiler_rt.so] Error 1
6 make: *** 正在等待未完成的任务....
7 host C++: dalvikvm_32 <= art/dalvikvm/dalvikvm.cc
8 
9 #### make failed to build some targets (01:27:58 (hh:mm:ss)) ####

  解决:
  1.art/build/Android.common_build.mk中把true改为false

# Host.
ART_HOST_CLANG := false
ifneq ($(WITHOUT_HOST_CLANG),false)          #ture--->false
# By default, host builds use clang for better warnings.
ART_HOST_CLANG := ture
endif

  2.执行命令,更改链接指向

ln -sf /usr/bin/ld.gold prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6/x86_64-linux/bin/ld

  原因:http://forum.xda-developers.com/chef-central/android/guide-how-to-setup-ubuntu-16-04-lts-t3363669/page2    的15楼  && 19楼

 
----------------------------------------------20160929------------------------------------

  Android编译:

 1 host C++: dex2oat <= art/dex2oat/dex2oat.cc
 2 In file included from art/runtime/atomic.h:21:0,
 3 from art/runtime/base/mutex.h:26,
 4 from art/runtime/utils.h:28,
 5 from art/runtime/base/histogram.h:23,
 6 from art/runtime/base/timing_logger.h:20,
 7 from art/dex2oat/dex2oat.cc:35:
 8 external/libcxx/include/atomic:539:2: error: #error <atomic> is not implemented
 9 In file included from art/runtime/base/mutex.h:26:0,
10 from art/runtime/utils.h:28,
11 from art/runtime/base/histogram.h:23,
12 from art/runtime/base/timing_logger.h:20,
13 from art/dex2oat/dex2oat.cc:35:
14 art/runtime/atomic.h: In static member function 'static void art::QuasiAtomic::ThreadFenceAcquire()':
15 art/runtime/atomic.h:155:5: error: 'atomic_thread_fence' is not a member of 'std'
16 art/runtime/atomic.h:155:30: error: 'memory_order_acquire' is not a member of 'std'
17 art/runtime/atomic.h: In static member function 'static void art::QuasiAtomic::ThreadFenceRelease()':
18 art/runtime/atomic.h:159:5: error: 'atomic_thread_fence' is not a member of 'std'
19 ...
20 ...
21 cc1plus: all warnings being treated as errors
22 
23 build/core/binary.mk:618: recipe for target 'out/host/linux-x86/obj32/EXECUTABLES/dex2oat_intermediates/dex2oat.o' failed
24 make: *** [out/host/linux-x86/obj32/EXECUTABLES/dex2oat_intermediates/dex2oat.o] Error 1
25 
26 #### make failed to build some targets (04:54 (mm:ss)) ####

  这个问题只怪自己曾经在搭4.4的环境的时候掉进了太多的坑,真是一点也不想动gcc等东西,所以虽然看到官方推荐使用GCC4.7.2,但依旧没有改(ubuntu16.04默认gcc5.4),在网上搜cc1plus: all warnings being treated as errors这个错误,给出的解决方案是注释掉Makefile文件中的-Werror指令,意思是不把warning当error这又害的我整了好几个小时去改Makefile文件中的-Werror指令,最后还是安装了gcc4.7,但是还是报错,后来就把所有的Makefile文件中的-Werror都注释掉了,坑爹啊!实际情况并不是这样子的啊!!

  解决:更新gcc/g++版本为4.7.4,编译成功。(若已经使用高版本gcc编译了一次,请重新download一份源码编译)
  原因:gcc版本过高,可能对C++的支持不好

 

  Android5.0编译我用的单线程花了我8个半小时。。。。。。。。以后还是用多线程编比较好,虽然并不稳定

1 #### make completed successfully (08:36:59 (hh:mm:ss)) ####

 

---------------------------------------------------20160930-------------------------------

  kernel  编译

 1 pngcui@Sky-pngcui:~/MSD6A828/l-828-0513/vendor/mstar/kernel/3.10.40$ make 
 2 HOSTCC scripts/basic/fixdep
 3 /usr/bin/ld: 当搜索用于 /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc.a 时跳过不兼容的 -lgcc
 4 /usr/bin/ld: 找不到 -lgcc
 5 /usr/bin/ld: 当搜索用于 /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so 时跳过不兼容的 -lgcc_s
 6 /usr/bin/ld: 找不到 -lgcc_s
 7 collect2: 错误: ld 返回 1
 8 scripts/Makefile.host:118: recipe for target 'scripts/basic/fixdep' failed
 9 make[2]: *** [scripts/basic/fixdep] Error 1
10 /home/pngcui/MSD6A828/l-828-0513/vendor/mstar/kernel/3.10.40/Makefile:453: recipe for target 'scripts_basic' failed
11 make[1]: *** [scripts_basic] Error 2
12 make: *** No rule to make target 'include/config/auto.conf', needed by 'include/config/kernel.release'。 停止。
13 
14 #### make failed to build some targets (1 seconds) ####

  解决:缺少gcc32位库,执行以下命令

sudo apt-get install g++-4.7-multilib

  搞定!

1 #### make completed successfully (08:44 (mm:ss)) ####

 

-------------------------------------------20171014---update-------------------------------------

 三、Ubuntu16.04.2编译Android5.1.1

1.平台:全志A64(Android5.1.1)

  编译Android:

    在解决 collect2: ld returned 1 exit status错误后,继续报如下错误

 1 Writing output...
 2 Preparing output jar [/home/pngcui/AW-A64/Android5.1/a64_android5.1/android/out/target/common/obj/APPS/TeleService_intermediates/proguard.classes.jar]
 3   Copying resources from program jar [/home/pngcui/AW-A64/Android5.1/a64_android5.1/android/out/target/common/obj/APPS/TeleService_intermediates/classes.jar]
 4 注: packages/apps/BasicSmsReceiver/tests/src/com/android/basicsmsreceiver/DialogSmsDisplayTests.java使用或覆盖了已过时的 API。
 5 注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
 6 target Java: CellBroadcastReceiverTests (out/target/common/obj/APPS/CellBroadcastReceiverTests_intermediates/classes)
 7 Preparing output jar [/home/pngcui/AW-A64/Android5.1/a64_android5.1/android/out/target/common/obj/APPS/TelephonyProvider_intermediates/proguard.classes.jar]
 8   Copying resources from program jar [/home/pngcui/AW-A64/Android5.1/a64_android5.1/android/out/target/common/obj/APPS/TelephonyProvider_intermediates/classes.jar]
 9 Checking API: checkpublicapi-last
10 Checking API: checkpublicapi-current
11 Checking API: checksystemapi-last
12 Checking API: checksystemapi-current
13 out/target/common/obj/PACKAGING/public_api.txt:20: error 5: Added public field android.Manifest.permission.BACKUP
14 out/target/common/obj/PACKAGING/public_api.txt:82: error 5: Added public field android.Manifest.permission.INVOKE_CARRIER_SETUP
15 out/target/common/obj/PACKAGING/public_api.txt:106: error 5: Added public field android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE
16 out/target/common/obj/PACKAGING/public_api.txt:116: error 5: Added public field android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST
17 
18 ******************************
19 You have tried to change the API from what has been previously approved.
20 
21 To make these errors go away, you have two choices:
22    1) You can add "@hide" javadoc comments to the methods, etc. listed in the
23       errors above.
24 
25    2) You can update current.txt by executing the following command:
26          make update-api
27 
28       To submit the revised current.txt to the main Android repository,
29       you will need approval.
30 ******************************
31 
32 
33 
34 make: *** [out/target/common/obj/PACKAGING/checkpublicapi-current-timestamp] 错误 38
35 make: *** 正在等待未完成的任务....
36 
37 #### make failed to build some targets (01:57:08 (hh:mm:ss)) ####

        那么根据提示,执行命令即可,然后再继续make进行编译

make update-api

 

 

##############20200618  update####################

平台:Android-P以上版本

需求:修改hidl接口,编译报错

报错1:

ERROR: android.hardware.camera.device@1.0::ICameraDevice has hash 0b82b6d63cb098f88756b4fb587df48695cf36d7ab1aadd6ce52d69085d42c17 which does not match hash on record. This interface has been frozen. Do not change it!

原因:Android P开始,Google对Hidl有了严格的限制,对Google release出来的hidl接口不允许修改。

解决方案:更新hidl的hash值到hardware/interfaces/current.txt中对应的hidl文件即可,若系统编译没有打印出hash值,可以使用如下命令生成

hidl-gen -L hash -r .:hardware/interfaces android.hardware.camera.device@1.0::ICameraDevice

报错2:

更新hash值之后,继续make,继续报错如下

error: VNDK library: android.hardware.camera.device@1.0's ABI has INCOMPATIBLE CHANGES Please check compatibility report at: out/soong/.intermediates/hardware/interfaces/camera/device/1.0/android.hardware.camera.device@1.0/android_arm_armv7-a-neon_cortex-a7_vendor_shared/android.hardware.camera.device@1.0.so.abidiff
******************************************************
error: Please update ABI references with: $ANDROID_BUILD_TOP/development/vndk/tools/header-checker/utils/create_reference_dumps.py  -l android.hardware.camera.device@1.0

解决方案:更新vndk的api,命令如下:

development/vndk/tools/header-checker/utils/create_reference_dumps.py  -l android.hardware.camera.device@1.0 -products (TARGET_PRODUCT)

注意:需要带-products参数,后面是编译TARGET_PRODUCT属性

 

 

##############20220109  update####################

平台:Android-R以上版本

需求:修改API接口,编译报错

Android11以上版本,google增加了lint工具对API接口函数进行自动检查,类似selinux的规范检查,由于本次项目是由Android10升级到Android12,为了兼容以前老接口,所以必须跳过这种检查,下面开始填坑

frameworks/base/core/java/android/hardware/Camera.java:4476: error: Must use ParcelFileDescriptor instead of FileDescriptor in parameter FileDescriptor in android.hardware.Camera.testApi************************************************************
Your API changes are triggering API Lint warnings or errors.
To make these errors go away, fix the code according to the
error and/or warning messages above.

If it is not possible to do so, there are workarounds:

1. You can suppress the errors with @SuppressLint("<id>")
2. You can add a baseline file of existing lint failures
   to the build rule of api-stubs-docs-non-updatable.
************************************************************
exit status 255
[  1% 6/339] //frameworks/base:test-api-stubs-docs-non-updatable metalava merged

按照提示1:在API接口上方增加@SuppressLint("<id>"),可以解决一些warning的报错,对于一些error: Must报错无法解决

于是继续按照提示2:add a baseline来跳过检查,查看Android.bp文件,增加对应baseline文件

frameworks/base$ git diff StubLibraries.bp
diff --git a/StubLibraries.bp b/StubLibraries.bp
old mode 100644
new mode 100755
index 44c55c26153d..551a314ee98e
--- a/StubLibraries.bp
+++ b/StubLibraries.bp
@@ -55,6 +55,7 @@ droidstubs {
         api_lint: {
             enabled: true,
             new_since: ":android.api.public.latest",
+            baseline_file: "core/api/lint-baseline.txt",
         },
     },
     dists: [

请注意看对应的api接口是在哪个api.txt中,然后增加到对应的baseline.txt中,Android12中有很多种api,如system-current.txt,module-lib-current.txt等等

增加完对应baseline.txt,不用手动去添加对应的规则,直接编译,不出意外的话会编译出错

frameworks/base/core/java/android/hardware/Camera.java:4657: error: Missing nullability on parameter `fileDescriptor` in method `awCamRecInit` [MissingNullability]
frameworks/base/core/java/android/hardware/Camera.java:4718: error: Missing nullability on parameter `parameters` in method `awCamRecSetParaAndCmds` [MissingNullability]
74 more error(s) omitted. Search the log for 'error:' to find all of them.
************************************************************
Your API changes are triggering API Lint warnings or errors.
To make these errors go away, fix the code according to the
error and/or warning messages above.

If it is not possible to do so, there are workarounds:

1. You can suppress the errors with @SuppressLint("<id>")
2. You can update the baseline by executing the following
   command:
       (cd $ANDROID_BUILD_TOP && cp \
       "out/soong/.intermediates/frameworks/base/api-stubs-docs-non-updatable/android_common/metalava/api_lint_baseline.txt" \
       "frameworks/base/core/api/lint-baseline.txt")
   To submit the revised baseline.txt to the main Android
   repository, you will need approval.
************************************************************

按照提示,我们直接把规则文件拷贝到baseline.txt文件中即可,不管他有多少条错误,都可以一次搞定

cd $ANDROID_BUILD_TOP
cp "out/soong/.intermediates/frameworks/base/api-stubs-docs-non-updatable/android_common/metalava/api_lint_baseline.txt" \
       "frameworks/base/core/api/lint-baseline.txt"

更新lint-baseline.txt文件后即可正常make update-api了

注:此方法是跳过lint的检查,但是真正开发的时候建议还是根据对应的规范进行修改代码,满足google的API接口规范

 

posted @ 2016-08-30 11:47  某某璀  阅读(23365)  评论(1编辑  收藏  举报
levels of contents