购买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

set it the default java version

$ sudo update-alternatives --config java
$ sudo update-alternatives --config javac

2.required package

sudo apt-get install bison g++-multilib git gperf libxml2-utils make python-networkx zlib1g-dev:i386 zip

遇到问题:

$ 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

按照如下步骤即可:

$ sudo apt-get install g++-multilib
$ sudo apt-get install  bison git gperf libxml2-utils make python-networkx zlib1g-dev:i386 zip

gcc为必须

$ sudo apt-get install gcc$ gcc -v
Thread model: posix
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04)

repo

$ mkdir ~/bin
$ PATH=~/bin:$PATH$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

check sh1 sum:

$ sha1sum repo
b8bd1804f432ecf1bab730949c82b93b0fc5fede  repo

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
$ repo init -u https://android.googlesource.com/platform/manifest -b android-5.1.1_r9Your identity is: linc <xxx@xxx.com>
If you want to change this, please re-run 'repo init' with --config-nameTesting 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

repo sync

$ repo sync

一个晚上两个白天,终于下载完成,代码达34G.

Setting up ccache

Put the following in your .bashrc (or equivalent):

export USE_CCACHE=1

run the command:

prebuilts/misc/linux-x86/ccache/ccache -M 50G

Building the System

1.Set up environment

$ source build/envsetup.sh

or

$ . build/envsetup.sh

2.Choose a Target

$ lunch You're building on LinuxLunch menu... pick a combo:1. aosp_arm-eng2. aosp_arm64-eng3. aosp_mips-eng4. aosp_mips64-eng5. aosp_x86-eng6. aosp_x86_64-eng7. aosp_manta-userdebug8. aosp_flo-userdebug9. aosp_deb-userdebug10. full_fugu-userdebug11. aosp_fugu-userdebug12. aosp_tilapia-userdebug13. aosp_grouper-userdebug14. aosp_mako-userdebug15. aosp_hammerhead-userdebug16. aosp_flounder-userdebug17. aosp_shamu-userdebug18. mini_emulator_x86-userdebug19. mini_emulator_arm64-userdebug20. mini_emulator_x86_64-userdebug21. mini_emulator_mips-userdebug22. m_e_arm-userdebugWhich would you like? [aosp_arm-eng] 

Nexus5就选择了15,如果只是用于模拟器就选择1好了。
3.build

make -j4

如果遇到等待其他任务完成的错误,是多线程冲突,就直接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

try make clean.这是没有安装gcc的后果。

build successfully

#### make completed successfully (05:53:54 (hh:mm:ss)) ####

目录结构如下:

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

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

Once the device is in fastboot mode, run

$ fastboot flashall -w

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: 69206016Block size: 4096Blocks per group: 32768Inodes per group: 4224Inode size: 256Journal blocks: 1024Label: Blocks: 16896Block groups: 1Reserved block group size: 7
Created filesystem with 11/4224 inodes and 1302/16896 blocks

模拟器顺利启动,与真机的区别有很多,比如开机画面不同,Home的UI和操控都有所不同。具体原因敬请期待。

Android实战技巧之四十:Android5.1.1源代码编译与烧写相关推荐

  1. Android实战技巧之四十 Android5 1 1源代码编译与烧写

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 购买Ne ...

  2. android 速度传感器,Android实战技巧之四十二:加速度传感器

    传感器字面上的意思就是传递感觉的仪器,哪些感觉呢? 视觉.听觉.味觉.触觉.嗅觉等等. 所以有人说,传感器的存在和发展,让物体有了触觉.味觉和嗅觉等感官,让物体慢慢变得活了起来. 当前Android设 ...

  3. Android实战技巧之十二:Android Studio导入第三方类库、jar包和so库

    第三方类库源码 将一网友的XMPP代码从ADT转到AS时,发现其使用了第三方类库,源码放在了lib下,直接在AS中Import project,第三方类库并没有自动导入进来,看来需要自己动手了. 项目 ...

  4. android studio导入jar包和so库,Android实战技巧之十二:Android Studio导入第三方类库、jar包和so库(示例代码)...

    第三方类库源码 将一网友的XMPP代码从ADT转到AS时,发现其使用了第三方类库,源码放在了lib下,直接在AS中Import project,第三方类库并没有自动导入进来,看来需要自己动手了. 项目 ...

  5. Android实战技巧之三十九:短信收发

    7月4日从广州出差回来就定下写作计划,但迟迟没有动笔.耽搁的原因还是老样子,工作上又有新任务,全部精力都投入过去了,每天精疲力竭的回来也打不起精神做其他事了.这就是精力管理不当所致,就像我把很多要做的 ...

  6. Android实战技巧之十:获得屏幕物理尺寸、密度及分辨率

    大家帮忙喽! 博主参加2014博客之星活动,大家帮忙投票啦!猛击这里! 通过程序去了解硬件情况是一件十分有意思的事情.很早我就研究在WM6.5上获得屏幕物理尺寸,但一直没有成功.后来又想要在Andro ...

  7. Android实战技巧之四十七:不用预览拍照与图片缩放剪裁

    副标题:Take Picture without preview Android Google出于对隐私的保护,制定了一条门槛,即在Android应用开发中编写拍照程序是必需要有图像预览的.这会对那些 ...

  8. Android实战技巧之十六:getprop与dumpsys命令

    Android设备连接PC后,我们可以通过adb命令完成绝大多数工作.下面借助getprop.dumpsys来了解一些系统相关信息. 一.getprop 此命令的原理很简单,就是从系统的各种配置文件中 ...

  9. Android实战技巧之十六 getprop与dumpsys命令

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! Andr ...

最新文章

  1. escape sequence
  2. hdu4901 枚举状态(找集合对S(xor) ==T(and))
  3. 分支结构,循环结构,for循环,九九乘法表
  4. android gps 串口,Android GPS数据上报(基于gps_qemu.c)
  5. Docker 精通之常用命令
  6. python处理大数据越来越慢_请问使用JdbcTemplate读取大数据很慢如何优化?(十几万数据)...
  7. 深度学习(六十一)NNPACK 移植与实验
  8. 高端的面试从来不会在HashMap的红黑树上纠缠太多
  9. Windows 2000活动目录详解之基础篇
  10. 基于M6097 switch的STP协议调试方法
  11. 算法速学速用大辞典 pdf_随机梯度蒙特卡洛算法-重要性采样
  12. python爬虫框架论文开题报告范文_研究思路及框架--开题报告
  13. 安卓神器-kiwi browser
  14. 4399PK3366 拭目以待
  15. Windows获取本机公网ip脚本
  16. uniapp使用ucharts图表及问题汇总
  17. krpano全景图切片还原和下载
  18. 一种求周期二元线性序列的极小多项式的方法
  19. UltraEdit的安装与破解
  20. 刷脸支付连锁化经营的商业形态完美融合

热门文章

  1. MultipleOutputFormat和MultipleOutputs
  2. 贴几张Google Earth的图
  3. 蓝桥杯 算法训练 Cowboys
  4. 康耐视visionpro工具大全
  5. python之xlrd
  6. 企业微信如何设置文件权限?
  7. 苏州项目申报公司告诉你软件著作权你不知道的还很多
  8. 微信小程序 实现客服功能 和 ICON标签
  9. Spring三级缓存源码
  10. 流年做戏,我不会再爱你