Android 4.0.1 源代码编译
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android 4.0.1 源代码编译相关的知识,希望对你有一定的参考价值。
在学习应用编程时,为了实现应用在后台对其它界面的控制,需要将应用的权限提高到系统级。
但提高到系统级的方法,其中一个就是放在 android 源代码目录中进行编译;另一个方法已经试过,但安装失败。
开始一直想直接从 Google 的网站上获取 Android 源代码,但由于大陆对 Google 的封锁,导致无法获取到。大家都通过 VPN 来获取,但一般 VPN 是需要费用的。
后来才将获取 Android 源代码的方向转向别人下载好,打包传到网上的。
先后从 XX 云盘下载了 3 个 Android 源代码压缩包,分别是:
repo.tar.gz 12.2GB
WORKING_DIRECTORY.tar 12.4GB
android4.0.tar.gz 1.73GB
前两个还没有使用过,先使用 android4.0.tar.gz 进行了试验。
在 Ubuntu 中先解压 android4.0.tar.gz: tar -zxvf android4.0.tar.gz
安装 jdk-6u45-linux-i586.bin,从 Oracle 网站上下载,需要在 Oracle 注册。
获取 jdk-6u45-linux-i586.bin 下载网址的办法: google "jdk-6u45-linux" 得到的第一个搜索结果:
http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html
注意: 不用使用 Ubuntu 提供的 open-jdk 的版本。
安装过程:
(1) 赋予执行权限,在 terminal 中输入: chmod a+x jdk-6u45-linux-i586.bin
(2) 解压,在 terminal 中输入: ./jdk-6u45-linux-i586.bin
(3) 创建 jvm 目录,在 terminal 中输入: sudo mkdir /usr/lib/jvm
(4) 移动解压文件,在 terminal 中输入: sudo mv ~/AndroidSource/android4.0/jdk1.6.0_45 /usr/lib/jvm/jdk1.6.0_45
(5) 启用 jdk 6,在 terminal 中输入:
sudo ln -s -b /usr/lib/jvm/jdk1.6.0_45/jre/bin/java /etc/alternatives/java
sudo ln -s -b /usr/lib/jvm/jdk1.6.0_45/jre/bin/java /usr/bin/java
(6) 检验,在 terminal 中输入:java -version
结果应显示:
java version "1.6.0_45"
(7) 编辑配置文件,在 terminal 中输入: sudo vim /etc/profile
在文件末尾添加如下条目:
JAVA_HOME=/usr/lib/jvm/jdk1.6.0_45
export JRE_HOME=/usr/lib/jvm/jdk1.6.0_45/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
#set java environment
这里要根据自己的安装路径对以上内容进行修改!重启系统后java的环境就安装好了。
注: vim 操作指令,(1) Insert 按键;(2) : ; (3)! ; (4) w/q
开始编译 Android 源代码,进入目录: ~/AndroidSource/android4.0,依次输入如下指令:
#make installclean
#make clean
#source build/envsetup.sh
#lunch 选择版本号: lunch full-eng
1. full-eng
2. full_x86-eng
3. vbox_x86-eng
4. full_maguro-userdebug
5. full_tuna-userdebug
6. full_panda-eng
Which would you like [full-eng] 5
#make -j4 其中-j(n)表示用n核cpu编译
如果出错如下错误,按对应方法解决:
(1) Ubuntu bison:找不到命令
sudo apt-get install g++
(2) Ubuntu g++:找不到命令
sudo apt-get install bison
(3) /usr/bin/ld: cannot find -lz
详细信息如下:
host C: libpng <= external/libpng/pngwtran.c
host C: libpng <= external/libpng/pngwutil.c
host StaticLib: libpng (out/host/linux-x86/obj/STATIC_LIBRARIES/libpng_intermediates/libpng.a)
host Executable: aapt (out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt)
/usr/bin/ld: cannot find -lz
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt] 错误 1
解决方法:
更新了工具的安装,如下:
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev libncurses5-dev x11proto-core-dev libx11-dev libreadline6-dev libgl1-mesa-dev tofrodos python-markdown libxml2-utils xsltproc
可以继续编译。
错误1:
编译过程中出现一次提示: 进程被杀掉的错误,并终止的现象。
当时没有记录具体的错误,重新编译就 OK 了。
------重新执行: make -j2
错误2:
t_intermediates/src -api out/target/common/obj/PACKAGING/public_api.txt -nodocs
make: *** 正在等待未完成的任务....
make: *** [out/target/common/docs/api-stubs-timestamp] 错误 45
解决方法(使用方法2):
(1) 网上一种解决方法(但我的 extenal 目录中没有 clearsilver 目录(有人说此方法适用于: Android 2.3))
是由于clearsilver在编译时如果检测到使用Java JDK 6,就使用64位编译。要避开此错误,需要修改下面四个文件:
external/clearsilver/cgi/Android.mk
external/clearsilver/java-jni/Android.mk
external/clearsilver/util/Android.mk
external/clearsilver/cs/Android.mk
把这四个Makefile中的下列语句注掉即可:
# This forces a 64-bit build for Java6
# Comment by Easwy
# LOCAL_CFLAGS += -m64
# LOCAL_LDFLAGS += -m64
然后在external/clearsilver目录中执行一下make clean,然后回到项目根目录,继续make即可。
(2) make clear/make update-api/make
(3) make: *** [out/target/common/docs/doc-comment-check-timestamp] 错误 45
解决方法:需要做个链接如下:
sudo ln -s /usr/lib/jvm/jdk1.6.0_45/bin/jar /bin/jar
sudo ln -s /usr/lib/jvm/jdk1.6.0_45/bin/java /bin/java
sudo ln -s /usr/lib/jvm/jdk1.6.0_45/bin/javac /bin/javac
sudo ln -s /usr/lib/jvm/jdk1.6.0_45/bin/javah /bin/javah
sudo ln -s /usr/lib/jvm/jdk1.6.0_45/bin/javadoc /bin/javadoc
错误:
prebuilt/linux-x86/toolchain/arm-linux-androideabi-4.4.x/bin/arm-linux-androideabi-ar: out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates/libwebcore.a: No space left on device
make: *** [out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates/libwebcore.a] 错误 1
make: *** 正在删除文件“out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates/libwebcore.a”
原因: 空间不足导致编译中断
挂载一个 20G 的空分区,重新解压 android4.0.tar.gz: tar -zxvf android4.0.tar.gz
make installclean
make clean
make update-api
source build/envsetup.sh
make -j2
错误:
nd/m_demangle/cplus-dem.c:2865: error: undefined reference to ‘vgPlain_strcspn‘
prebuilt/linux-x86/toolchain/arm-linux-androideabi-4.4.x/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: out/target/product/generic/obj/STATIC_LIBRARIES/libcoregrind-arm-linux_intermediates/libcoregrind-arm-linux.a(cplus-dem.o): in function gnu_special:external/valgrind/main/coregrind/m_demangle/cplus-dem.c:2926: error: undefined reference to ‘vgPlain_strpbrk‘
collect2: ld returned 1 exit status
make: *** [out/target/product/generic/obj/SHARED_LIBRARIES/cachegrind-arm-linux_intermediates/LINKED/cachegrind-arm-linux] 错误 1
原因: 没有执行 lunch
错误:
target StaticLib: libwebcore (out/target/product/tuna/obj/STATIC_LIBRARIES/libwebcore_intermediates/libwebcore.a)
prebuilt/linux-x86/toolchain/arm-linux-androideabi-4.4.x/bin/arm-linux-androideabi-ar: out/target/product/tuna/obj/STATIC_LIBRARIES/libwebcore_intermediates/libwebcore.a: No space left on device
make: *** [out/target/product/tuna/obj/STATIC_LIBRARIES/libwebcore_intermediates/libwebcore.a] 错误 1
make: *** 正在删除文件“out/target/product/tuna/obj/STATIC_LIBRARIES/libwebcore_intermediates/libwebcore.a”
/usr/bin/ld: final link failed: No space left on device
collect2: ld returned 1 exit status
make: *** 正在等待未完成的任务....
make: *** [out/host/linux-x86/obj/lib/libbcc.so] 错误 1
挂载一个 20G 的空分区后编译 Android 4.0.1 的源代码,仍然出现: No space left on device。所以一狠心,将现在用的 Ubuntu 虚拟机删除了,重建一个 80G 的虚拟机。
使用 Ubuntu 10.04,安装后不做任何升级。
以下是操作过程中对硬盘剩余空间的记录:
(1) 80G 安装 Ubuntu 后剩余 69.7 GB
(2) 复制 android4.0.tar.gz 和 jdk-6u45-linux-i586.bin 后,解压: tar -zxvf android4.0.tar.gz 后剩余 61.4 GB
(3)准备好编译环境后(删除 android4.0.tar.gz 和 jdk-6u45-linux-i586.bin),剩余空间 62.9 GB
开始编译 Android 4.0.1 源代码。
如果编译过程中出现错误,只要编译环境的配置是正确的,就不要试着去解决它。只需要简单的重新编译即可!编译成功后,剩余的空间是 51.1 GB。
编译 Android 4.0.1 源代码,至少需要 18.6G 的硬盘空间。
编译成功结束时的 LOG:
Target system fs image: out/target/product/tuna/obj/PACKAGING/systemimage_intermediates/system.img
in mkuserimg.sh PATH=out/host/linux-x86/bin/:/usr/lib/jvm/java-6-sun/bin:/usr/lib/jvm/jdk1.6.0_45/bin:/usr/lib/jvm/jdk1.6.0_45/jre/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/leozheng/android4.0/out/host/linux-x86/bin:/home/leozheng/android4.0/prebuilt/linux-x86/toolchain/arm-linux-androideabi-4.4.x/bin:/home/leozheng/android4.0/development/emulator/qtools:/home/leozheng/android4.0/prebuilt/linux-x86/toolchain/arm-linux-androideabi-4.4.x/bin:/home/leozheng/android4.0/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin
make_ext4fs -s -l 685768704 -a system out/target/product/tuna/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/tuna/system
Creating filesystem with parameters:
Size: 685768704
Block size: 4096
Blocks per group: 32768
Inodes per group: 6976
Inode size: 256
Journal blocks: 2616
Label:
Blocks: 167424
Block groups: 6
Reserved block group size: 47
Created filesystem with 904/41856 inodes and 41089/167424 blocks
Install system fs image: out/target/product/tuna/system.img
out/target/product/tuna/system.img+out/target/product/tuna/obj/PACKAGING/recovery_patch_intermediates/recovery_from_boot.p total size is 159017016
启动编译后的 Android 4.0.1 模拟器
[email protected]:~$ ls
android4.0 Documents examples.desktop Pictures Templates
Desktop Downloads Music Public Videos
[email protected]:~$ cd android4.0/out/host/linux-x86/bin
按网上的说明,要进入 sdk 目录。但此目录不存在,会提示 bash: cd: sdk: No such file or directory
[email protected]:~/android4.0/out/host/linux-x86/bin$ ls
......
[email protected]:~/android4.0/out/host/linux-x86/bin$ ls em*
emulator emulator-arm emulator-ui emulator-x86
[email protected]:~/android4.0/out/host/linux-x86/bin$ ./emulator
emulator: ERROR: You did not specify a virtual device name, and the system
directory could not be found.
If you are an Android SDK user, please use ‘@<name>‘ or ‘-avd <name>‘
to start a given virtual device (see -help-avd for details).
Otherwise, follow the instructions in -help-disk-images to start the emulator
[email protected]:~/android4.0/out/host/linux-x86/bin$ ./emulator list targets
invalid command-line parameter: list.
Hint: use ‘@foo‘ to launch a virtual device named ‘foo‘.
please use -help for more information
[email protected]:~/android4.0/out/host/linux-x86/bin$ ls an*
android
[email protected]:~/android4.0/out/host/linux-x86/bin$ android list targets
android: command not found
[email protected]:~/android4.0/out/host/linux-x86/bin$ ./android list targets
SWT folder ‘/home/leozheng/android4.0/out/host/linux-x86/framework/x86‘ does not exist.
Please export ANDROID_SWT to point to the folder containing swt.jar for your platform.
[email protected]:~/android4.0/out/host/linux-x86/bin$ export PATH=~/android4.0/out/host/linux-x86/bin:$PATH
[email protected]:~/android4.0/out/host/linux-x86/bin$ export ANDROID_PRODUCT_OUT=~/android4.0/out/target/product/generic
[email protected]:~/android4.0/out/host/linux-x86/bin$ emulator
emulator: ERROR: Can‘t access ANDROID_PRODUCT_OUT as ‘/home/leozheng/android4.0/out/target/product/generic‘
You need to build the Android system before launching the emulator
[email protected]:~/android4.0/out/host/linux-x86/bin$ cd ..
[email protected]:~/android4.0/out/host/linux-x86$ cd ..
[email protected]:~/android4.0/out/host$ cd ..
[email protected]:~/android4.0/out$ ls
casecheck.txt CaseCheck.txt host target versions_checked.mk
[email protected]:~/android4.0/out$ cd target/
[email protected]:~/android4.0/out/target$ ls
common product
[email protected]:~/android4.0/out/target$ cd product
[email protected]:~/android4.0/out/target/product$ ls
tuna
[email protected]:~/android4.0/out/target/product$ cd tuna
[email protected]:~/android4.0/out/target/product/tuna$ ls
android-info.txt kernel recovery.img
boot.img obj root
clean_steps.mk previous_build_config.mk symbols
data ramdisk.img system
fake_packages ramdisk-recovery.img system.img
installed-files.txt recovery userdata.img
[email protected]:~/android4.0/out/target/product/tuna$ export ANDROID_PRODUCT_OUT=~/android4.0/out/target/product/tuna
[email protected]:~/android4.0/out/target/product/tuna$ emulator
模拟器启动成功,运行中...
如果提示:
emulator: WARNING: system partition size adjusted to match image file (152 MB > 66 MB)
emulator: WARNING: data partition size adjusted to match image file (135 MB > 66 MB)
emulator: emulator window was out of view and was recentered
如果在笔记本(1280*800分辨率)上用,skin的显示区域太大,键盘部分可能显示不全,给使用带来不便
以下网上记录的别人编译 Android V4.0.1 时遇到的问题与解决方法:
(*1) usr/bin/ld: cannot find libncurses.so.5 cannot find -lGL
sudo apt-get install git-core gnupg flex bison gperfbuild-essential zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libsx11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev libgl1-mesa-devg++-multilib
解决方法:
sudo ln -s /usr/lib/i386-linux-gnu/libX11.so.6 /usr/lib/i386-linux-gnu/libX11.so
(*2)
host SharedLib: lib64EGL_translator (out/host/linux-x86/obj/lib/lib64EGL_translator.so)
/usr/bin/ld: cannot find -lGL
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/lib/lib64EGL_translator.so] Error 1
make: *** Waiting for unfinished jobs....
解决方法:
sudo apt-get install libglu1-mesa-dev
NDK 安装
http://developer.android.com/tools/sdk/ndk/index.html
ndk$ chmod a+x android-ndk-r10c-darwin-x86_64.bin
ndk$ ./android-ndk-r10c-darwin-x86_64.bin
(*3)
host SharedLib: lib64EGL_translator (out/host/linux-x86/obj/lib/lib64EGL_translator.so)
/usr/bin/ld: cannot find -lGL
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/lib/lib64EGL_translator.so] Error 1
make: *** Waiting for unfinished jobs....
解决方法 :
sudo apt-get install libglu1-mesa-dev
(*4)
host StaticLib: libGLcommon (out/host/linux-x86/obj/STATIC_LIBRARIES/libGLcommon
_intermediates/libGLcommon.a)
host SharedLib: libGLES_CM_translator (out/host/linux-x86/obj/lib/libGLES_CM_tra
nslator.so)
/usr/bin/ld: cannot find -lGL
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/lib/libGLES_CM_translator.so] Error 1
解决方法:
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1.2 /usr/lib/libGL.so
以上是关于Android 4.0.1 源代码编译的主要内容,如果未能解决你的问题,请参考以下文章
Android studio 升级到4.0-4.0.1版本项目编译异常问题总结
如何使用 Visual Studio 编译器使用 cgo 构建库?
如何在32位ubuntu11.10 下编译android 4.0.1源码和goldfish内核