前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[ Andriod篇 ] - Android 5.0.2 源码编译

[ Andriod篇 ] - Android 5.0.2 源码编译

作者头像
程序手艺人
发布2019-02-20 17:15:20
2.4K0
发布2019-02-20 17:15:20
举报
文章被收录于专栏:程序手艺人

Android 源码版本比较多, 这里选择的是 韦东山第四期 Andriod 教程中的 Android-5.0.2, 直接从百问网公开的百度网盘链接下载。由于源码本身已经集成了 Tiny 4412开发板相关配置,省去了很多工作量。

百问网提供配置好编译环境的虚拟机,初步使用了一段时间,诸多不便,这里记录下在Ubuntu 18.04 编译源码的过程。 更方便的是使用Docker安装编译环境,一次配置即可。

构建环境

编译安卓源码之前,需要安装一些依赖包,最好的方式看官网文档 Establishing a Build Environment ,写的比较详细。

安装JDK
  • 每个Android 需要的JDK版本是不一样。这里Android 5.0.2 需要安装 OpenJDK 7 , 如下:
代码语言:javascript
复制
➜  bin java -version
java version "1.7.0_161"
OpenJDK Runtime Environment (IcedTea 2.6.12) (7u161-2.6.12-1)
OpenJDK 64-Bit Server VM (build 24.161-b01, mixed mode)
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
代码语言:javascript
复制
// 如果安装JDK不是7,编译报错如下:
make -j4 

PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=5.0.2
TARGET_PRODUCT=full_tiny4412
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=cortex-a9
TARGET_2ND_ARCH=
TARGET_2ND_ARCH_VARIANT=
TARGET_2ND_CPU_VARIANT=
HOST_ARCH=x86_64
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.4.0-116-generic-x86_64-with-Ubuntu-16.04-xenial
HOST_BUILD_TYPE=release
BUILD_ID=LRX22G
OUT_DIR=out
============================================
Checking build tools versions...
/bin/bash: javac: command not found
************************************************************
You are attempting to build with the incorrect version
of java.
 
Your version is: openjdk version "1.8.0_151" OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12) OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode).
The required version is: "1.7.x"
 
Please follow the machine setup instructions at
    https://source.android.com/source/initializing.html
************************************************************
build/core/main.mk:167: *** stop.  Stop.

#### make failed to build some targets (16 seconds) ####
安装依赖包
  • 官方文档 给出的详细介绍,每个Ubuntu 版本安装的依赖项略有区别
在这里插入图片描述
在这里插入图片描述
代码语言:javascript
复制
// 本机 Ubuntu 18.04  安装的依赖项
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev libgl1-mesa-dev libxml2-utils xsltproc unzip
编译
  • 设置环境变量,执行 android-5.0.2 中的 setenv
  • 执行 lunch,选择对应的板级配置,这里选择 full_tiny4412-eng
  • 执行make,开始编译,通过**-j**选择CPU核数,加速编译的过程。 一般3~4h,编译过程中,会出现编译错误,解决错误之后,继续编译即可。
  • 执行gen-img.sh,生成固件
编译报错解决

实际编译过程中,有一些编译错误,总结一下,并给出解决方案 。


  • /bin/bash: prebuilts/misc/linux-x86/bison/bison: No such file or directory

参考 failed to build aosp. says subcommand failed

解决方案

代码语言:javascript
复制
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386

  • prebuilts/misc/linux-x86/bison/bison: m4 subprocess failed:

解决方案

代码语言:javascript
复制
sudo apt-get install bison 

  • flex-2.5.39: loadlocale.c:130: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))’ failed.

参考 ubuntu 18.04 编译android 8.1 问题记录

Error when build LineageOS: “make: *** [ninja_wrapper] Error 1”

解决方案

代码语言:javascript
复制
export LC_ALL=C

  • opy xml: out/target/product/tiny4412/system/etc/apns-conf.xml Copy xml: out/target/product/tiny4412/system/etc/permissions/handheld_core_hardware.xml /bin/bash: xmllint: command not found /bin/bash: xmllint: command not found

解决方案

代码语言:javascript
复制
 sudo apt-get  install libxml2-utils 

  • clang: error: linker command failed with exit code 1 (use -v to see invocation)
代码语言:javascript
复制
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/include/c++/4.6/bits/basic_string.h:270: error: unsupported reloc 43
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/include/c++/4.6/bits/basic_string.h:270: error: unsupported reloc 43
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/include/c++/4.6/bits/basic_string.h:235: error: unsupported reloc 43
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/include/c++/4.6/bits/basic_string.h:235: error: unsupported reloc 43

libnativehelper/JNIHelp.cpp:338: error: unsupported reloc 43
libnativehelper/JniConstants.cpp:89: error: unsupported reloc 43
..............

clang: error: linker command failed with exit code 1 (use -v to see invocation)
build/core/host_shared_library_internal.mk:44: recipe for target 'out/host/linux-x86/obj32/lib/libnativehelper.so' failed
make: *** [out/host/linux-x86/obj32/lib/libnativehelper.so] Error 1
make: *** Waiting for unfinished jobs....

#### make failed to build some targets (46:54 (mm:ss)) ####

参考Android build error on Ubuntu 16.04 LTS 该方法无效

Ubuntu16 编译Android5.1 lollipop 源码出错 unsupported reloc 43 采用该方法解决

解决方案

代码语言:javascript
复制
cp /usr/bin/ld.gold prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6/x86_64-linux/bin/ld

  • 在源码编译3h之后报的错误
代码语言:javascript
复制
Copying: out/target/common/obj/APPS/Bluetooth_intermediates/noproguard.classes.jar
target SharedLib: libGLES_trace (out/target/product/tiny4412/obj/SHARED_LIBRARIES/libGLES_trace_intermediates/LINKED/libGLES_trace.so)
target SharedLib: libbinder (out/target/product/tiny4412/obj/SHARED_LIBRARIES/libbinder_intermediates/LINKED/libbinder.so)
target Symbolic: libharfbuzz_ng (out/target/product/tiny4412/symbols/system/lib/libharfbuzz_ng.so)
out/target/common/obj/PACKAGING/public_api.txt:20: error 5: Added public field android.Manifest.permission.BACKUP
out/target/common/obj/PACKAGING/public_api.txt:81: error 5: Added public field android.Manifest.permission.INVOKE_CARRIER_SETUP
out/target/common/obj/PACKAGING/public_api.txt:105: error 5: Added public field android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE
out/target/common/obj/PACKAGING/public_api.txt:115: error 5: Added public field android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST

******************************
You have tried to change the API from what has been previously approved.

To make these errors go away, you have two choices:
   1) You can add "@hide" javadoc comments to the methods, etc. listed in the
      errors above.

   2) You can update current.txt by executing the following command:
         make update-api

      To submit the revised current.txt to the main Android repository,
      you will need approval.
******************************

build/core/tasks/apicheck.mk:57: recipe for target 'out/target/common/obj/PACKAGING/checkapi-current-timestamp' failed
make: *** [out/target/common/obj/PACKAGING/checkapi-current-timestamp] Error 38
make: *** Waiting for unfinished jobs....
target SharedLib: libbcc (out/target/product/tiny4412/obj/SHARED_LIBRARIES/libbcc_intermediates/LINKED/libbcc.so)
clang: warning: argument unused during compilation: '-nodefaultlibs'
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

#### make failed to build some targets (03:18:04 (hh:mm:ss)) ####

参考[How to fix this API error](make update-api && make -j4make update-api && make -j4make update-api && make -j4)

解决方案

代码语言:javascript
复制
make update-api && make -j4

顺利编译完成,整体编译大约持续4h

代码语言:javascript
复制
Install: out/target/product/tiny4412/system/lib/libwebviewchromium.so
Install: out/target/product/tiny4412/system/app/webview/webview.apk
mkdir -p out/target/product/tiny4412/system/app/webview/lib/arm  ;ln -sf /system/lib/libwebviewchromium.so out/target/product/tiny4412/system/app/webview/lib/arm/libwebviewchromium.so
build/tools/generate-notice-files.py  out/target/product/tiny4412/obj/NOTICE.txt  out/target/product/tiny4412/obj/NOTICE.html "Notices for files contained in the filesystem images in this directory:" out/target/product/tiny4412/obj/NOTICE_FILES/src
Combining NOTICE files into HTML
Combining NOTICE files into text
Installed file list: out/target/product/tiny4412/installed-files.txt
Target system fs image: out/target/product/tiny4412/obj/PACKAGING/systemimage_intermediates/system.img
Running:  mkuserimg.sh -s out/target/product/tiny4412/system out/target/product/tiny4412/obj/PACKAGING/systemimage_intermediates/system.img ext4 system 629145600 out/target/product/tiny4412/root/file_contexts
make_ext4fs -s -T -1 -S out/target/product/tiny4412/root/file_contexts -l 629145600 -a system out/target/product/tiny4412/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/tiny4412/system
Creating filesystem with parameters:
    Size: 629145600
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 7680
    Inode size: 256
    Journal blocks: 2400
    Label: 
    Blocks: 153600
    Block groups: 5
    Reserved block group size: 39
Created filesystem with 1874/38400 inodes and 136196/153600 blocks
Install system fs image: out/target/product/tiny4412/system.img
out/target/product/tiny4412/system.img+ maxsize=642318336 blocksize=4224 total=549692400 reserve=6488064

#### make completed successfully (39:39 (mm:ss)) ####

  • ./gen-img.sh: line 31: mkimage: command not found

编译 u-boot 得到 mkimage 工具,并拷贝到 /usr/bin路径

代码语言:javascript
复制
sudo cp tools/mkimage /usr/bin/

参考的博客
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019年01月13日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 构建环境
  • 安装JDK
  • 安装依赖包
  • 编译
  • 编译报错解决
  • 参考的博客
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档