随时随地阅读更多技术实战干货,获取项目源码、学习资料,请关注源代码社区公众号(ydmsq666)
转自:http://blog.csdn.net/lincyang/article/details/48197787
购买Nexus手机的朋友大多是为了自己修改系统玩,再加上其较高的性价比,在开发者中还是广受欢迎的。我的5太子被我升级到了6.0预览版,玩的正嗨,舍不得换回到5.1时代了。不过鉴于距6.0源码发布还有段日子,5.1的源码编译与烧写仍是主流,下面就记录了整个过程(持续了很长时间,我们要有耐心)。
搭建开发环境
系统推荐Ubuntu 14.04
1.openjdk is needed
$ sudo apt-get update
$ sudo apt-get install openjdk-7-jdk
- 1
- 2
- 1
- 2
set it the default Java version
$ sudo update-alternatives --config java
$ sudo update-alternatives --config javac
- 1
- 2
- 1
- 2
2.required package
sudo apt-get install bison g++-multilib git gperf libxml2-utils make python-networkx zlib1g-dev:i386 zip
- 1
- 1
遇到问题:
$ sudo apt-get install bison g++-multilib git gperf libxml2-utils make python-networkx zlib1g-dev:i386 zip
[sudo] password for linc:
Reading package lists... Done
Building dependency tree
Reading state information... Done
make is already the newest version.
zip is already the newest version.
git is already the newest version.
git set to manually installed.
libxml2-utils is already the newest version.
libxml2-utils set to manually installed.
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
g++-multilib : Depends: gcc-multilib (>= 4:4.8.2-1ubuntu6) but it is not going to be installed
E: Unable to correct problems, you have held broken packages
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
按照如下步骤即可:
$ sudo apt-get install g++-multilib
$ sudo apt-get install bison git gperf libxml2-utils make python-networkx zlib1g-dev:i386 zip
- 1
- 2
- 1
- 2
gcc为必须
$ sudo apt-get install gcc
$ gcc -v
Thread model: posix
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04)
- 1
- 2
- 3
- 4
- 5
- 6
- 1
- 2
- 3
- 4
- 5
- 6
repo
$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
check sh1 sum:
$ sha1sum repo
b8bd1804f432ecf1bab730949c82b93b0fc5fede repo
- 1
- 2
- 3
- 1
- 2
- 3
For version 1.21, the SHA-1 checksum for repo is b8bd1804f432ecf1bab730949c82b93b0fc5fede
repo init
针对Nexus5的5.1.1的初始化如下:
LMY48I android-5.1.1_r9 Lollipop Nexus 4, Nexus 5, Nexus 6, Nexus 7 (flo), Nexus 9 (volantis/volantisg), Nexus 10
- 1
- 1
$ repo init -u https://android.googlesource.com/platform/manifest -b android-5.1.1_r9
Your identity is: linc <xxx@xxx.com>
If you want to change this, please re-run 'repo init' with --config-name
Testing colorized output (for 'repo diff', 'repo status'):
black red green yellow blue magenta cyan white
bold dim ul reverse
repo has been initialized in /home/linc/source-android/android-source
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
repo sync
$ repo sync
- 1
- 1
一个晚上两个白天,终于下载完成,代码达34G.
Setting up ccache
Put the following in your .bashrc (or equivalent):
export USE_CCACHE=1
- 1
- 1
run the command:
prebuilts/misc/linux-x86/ccache/ccache -M 50G
- 1
- 1
Building the System
1.Set up environment
$ source build/envsetup.sh
- 1
- 1
or
$ . build/envsetup.sh
- 1
- 1
2.Choose a Target
$ lunch
You're building on Linux
Lunch menu... pick a combo:
1. aosp_arm-eng
2. aosp_arm64-eng
3. aosp_mips-eng
4. aosp_mips64-eng
5. aosp_x86-eng
6. aosp_x86_64-eng
7. aosp_manta-userdebug
8. aosp_flo-userdebug
9. aosp_deb-userdebug
10. full_fugu-userdebug
11. aosp_fugu-userdebug
12. aosp_tilapia-userdebug
13. aosp_grouper-userdebug
14. aosp_mako-userdebug
15. aosp_hammerhead-userdebug
16. aosp_flounder-userdebug
17. aosp_shamu-userdebug
18. mini_emulator_x86-userdebug
19. mini_emulator_arm64-userdebug
20. mini_emulator_x86_64-userdebug
21. mini_emulator_mips-userdebug
22. m_e_arm-userdebug
Which would you like? [aosp_arm-eng]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
Nexus5就选择了15,如果只是用于模拟器就选择1好了。
3.build
make -j4
- 1
- 1
如果遇到等待其他任务完成的错误,是多线程冲突,就直接make好了。
4.error
1)
No private recovery resources for TARGET_DEVICE hammerhead
host C++: bcc <= frameworks/compile/libbcc/tools/bcc/Main.cpp
clang++: error: unable to execute command: Executable "as" doesn't exist!
clang++: error: assembler command failed with exit code 1 (use -v to see invocation)
make: *** [out/host/linux-x86/obj32/EXECUTABLES/bcc_intermediates/Main.o] Error 1
- 1
- 2
- 3
- 4
- 5
- 6
- 1
- 2
- 3
- 4
- 5
- 6
try make clean.这是没有安装gcc的后果。
build successfully
#### make completed successfully (05:53:54 (hh:mm:ss)) ####
- 1
- 1
目录结构如下:
out/target/product/hammerhead$ du -sh *
4.0K android-info.txt
8.8M boot.img
4.0K cache
14M cache.img
64K clean_steps.mk
172K data
4.0K fake_packages
81M gen
64K installed-files.txt
8.1M kernel
16G obj
4.0K previous_build_config.mk
700K ramdisk.img
1.4M ramdisk-recovery.img
2.2M recovery
9.5M recovery.img
1.3M root
2.9G symbols
288M system
307M system.img
135M userdata.img
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
Flash device
To flash a device, you will need to use fastboot, which should be included in your path after a successful build. Place the device in fastboot mode either manually by holding the appropriate key combination at boot, or from the shell with
$ adb reboot bootloader
- 1
- 1
Once the device is in fastboot mode, run
$ fastboot flashall -w
- 1
- 1
The -w option wipes the /data partition on the device; this is useful for your first time flashing a particular device but is otherwise unnecessary.
For more information about building for and running on actual hardware, see Running Builds.
Flash emulator
1.build generic img
lunch 1即可,然后正常make。
make completed successfully (05:02:47 (hh:mm:ss))
2.启动模拟器
~/source-android/android-source/out/target/product/generic$ emulator -sysdir ~/source-android/android-source/out/target/product/generic -system system.img
emulator: WARNING: system partition size adjusted to match image file (550 MB > 200 MB)
emulator: WARNING: data partition size adjusted to match image file (550 MB > 200 MB)
Creating filesystem with parameters:
Size: 69206016
Block size: 4096
Blocks per group: 32768
Inodes per group: 4224
Inode size: 256
Journal blocks: 1024
Label:
Blocks: 16896
Block groups: 1
Reserved block group size: 7
Created filesystem with 11/4224 inodes and 1302/16896 blocks
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
模拟器顺利启动,与真机的区别有很多,比如开机画面不同,Home的UI和操控都有所不同。具体原因敬请期待。