【开发指南】如何为nexus 5编译固件

nexus 5是谷歌的亲儿子,而android的源码是开源的,那如果我有一个nexus 5手机,为何不自己为nexus 5编译软件呢?

开搞,本文假定已经有android 5.1的源码并已经配置好开发环境,如果没有则参考google官方文档下载源码并配置开发环境。参考https://source.android.com/source/initializing.html以及https://source.android.com/source/downloading.html。注意,这个过程可能需要翻墙,作为程序员的我们,翻墙不是小菜一碟。

另外你需要知道AOSP,AOSP即Android Open Source Project 汉语意思是:谷歌开放源代码项目。我们通过Google官方下载的源代码,就是AOSP的代码,其中是不包含Google开发的那些个应用的,各个厂商拿到的也是这个版本,在这个版本的基础上进行修改。而Google发布的工厂固件则是包含全套Google服务的。厂商如果想安装Google服务,就需要过Google的那一套认证,比较麻烦,而且价格不菲,鉴于Google在国内的尴尬地位,国内很多厂商都没有过这个认证。所以,我们自己编译的出来的软件和nexus 5官方放出来的刷机包还是有区别的。

1. 初始化编译环境

. build/envsetup.sh

2. 加载机型

lunch

3. 选择要编译的机器

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_shamu-userdebug
     8. aosp_manta-userdebug
     9. full_fugu-userdebug
     10. aosp_fugu-userdebug
     11. aosp_grouper-userdebug
     12. aosp_tilapia-userdebug
     13. aosp_deb-userdebug
     14. aosp_flo-userdebug
     15. aosp_mako-userdebug
     16. aosp_hammerhead-userdebug
     17. aosp_flounder-userdebug
     18. mini_emulator_x86_64-userdebug
     19. mini_emulator_arm-userdebug
     20. mini_emulator_x86-userdebug
     21. mini_emulator_mips-userdebug
     22. mini_emulator_arm64-userdebug

3.1 机型对照表

Device

Code name

Build configuration

Nexus 6

shamu

aosp_shamu-userdebug

Nexus Player

fugu

aosp_fugu-userdebug

Nexus 9

volantis (flounder)

aosp_flounder-userdebug

Nexus 5 (GSM/LTE)

hammerhead

aosp_hammerhead-userdebug

Nexus 7 (Wi-Fi)

razor (flo)

aosp_flo-userdebug

Nexus 7 (Mobile)

razorg (deb)

aosp_deb-userdebug

Nexus 10

mantaray (manta)

full_manta-userdebug

Nexus 4

occam (mako)

full_mako-userdebug

Nexus 7 (Wi-Fi)

nakasi (grouper)

full_grouper-userdebug

Nexus 7 (Mobile)

nakasig (tilapia)

full_tilapia-userdebug

Galaxy Nexus (GSM/HSPA+)

yakju (maguro)

full_maguro-userdebug

Galaxy Nexus (Verizon)

mysid (toro)

aosp_toro-userdebug

Galaxy Nexus (Experimental)

mysidspr (toroplus)

aosp_toroplus-userdebug

PandaBoard (Archived)

panda

aosp_panda-userdebug

Motorola Xoom (U.S. Wi-Fi)

wingray

full_wingray-userdebug

Nexus S

soju (crespo)

full_crespo-userdebug

Nexus S 4G

sojus (crespo4g)

full_crespo4g-userdebug

3.2 三个版本说明版本

user

limited access; suited for production

userdebug

like “user” but with root access and debuggability; preferred for debugging

eng

development configuration with additional debugging tools

选择aosp_hammerhead-userdebug之后,会有下面的确认信息:

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=5.0.50.50.50.50
TARGET_PRODUCT=aosp_hammerhead
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=krait
TARGET_2ND_ARCH=
TARGET_2ND_ARCH_VARIANT=
TARGET_2ND_CPU_VARIANT=
HOST_ARCH=x86_64
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.13.0-37-generic-x86_64-with-Ubuntu-14.10-utopic
HOST_BUILD_TYPE=release
BUILD_ID=AOSP
OUT_DIR=out
============================================

4.生成驱动目录

接下来需要在Android官网下载 Nexus5所需要的驱动:https://developers.google.com/android/nexus/drivers#hammerheadlrx22c

下载完成后,解压出来是三个.sh文件,放到Android源码目录下面,然后执行.会将相关驱动放到vender目录下面.

5. 执行编译命令

make -j8

如果没有出错的话,在经过漫长的时间之后,编译成功:

6. 刷机命令

Nexus5关机状态下,长按音量下+电源,即可进入recovery模式, 然后在源码根目录下执行下面命令:

fastboot -w flashall

刷机成功后会自动重启

~/ fastboot -w flashall
target reported max download size of 1073741824 bytes
Creating filesystem with parameters:
    Size: 13725835264
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 8144
    Inode size: 256
    Journal blocks: 32768
    Label: 
    Blocks: 3351034
    Block groups: 103
    Reserved block group size: 823
Created filesystem with 11/838832 inodes and 93654/3351034 blocks
Creating filesystem with parameters:
    Size: 734003200
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 7472
    Inode size: 256
    Journal blocks: 2800
    Label: 
    Blocks: 179200
    Block groups: 6
    Reserved block group size: 47
Created filesystem with 11/44832 inodes and 5813/179200 blocks
--------------------------------------------
Bootloader Version...: HHZ12d
Baseband Version.....: M8974A-2.0.50.2.22
Serial Number........: 08ade1a513dc087b
--------------------------------------------
checking product...
OKAY [  0.100s]
sending 'boot' (8950 KB)...
OKAY [  0.500s]
writing 'boot'...
OKAY [  0.784s]
sending 'recovery' (9672 KB)...
OKAY [  0.556s]
writing 'recovery'...
OKAY [  0.814s]
erasing 'system'...
OKAY [  1.166s]
sending 'system' (328187 KB)...
OKAY [ 10.501s]
writing 'system'...
OKAY [ 23.623s]
erasing 'userdata'...
OKAY [ 14.657s]
sending 'userdata' (137318 KB)...
OKAY [  4.520s]
writing 'userdata'...
OKAY [  9.776s]
erasing 'cache'...
OKAY [  0.618s]
sending 'cache' (13348 KB)...
OKAY [  0.630s]
writing 'cache'...
OKAY [  1.070s]
rebooting...
finished. total time: 70.095s

原文发布于微信公众号 - 程序员互动联盟(coder_online)

原文发表时间:2015-08-21

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏杨龙飞前端

scrollto 到指定位置

2484
来自专栏张善友的专栏

LINQ via C# 系列文章

LINQ via C# Recently I am giving a series of talk on LINQ. the name “LINQ via C...

2605
来自专栏我和未来有约会

Silverlight第三方控件专题

这里我收集整理了目前网上silverlight第三方控件的专题,若果有所遗漏请告知我一下。 名称 简介 截图 telerik 商 RadC...

3955
来自专栏一个爱瞎折腾的程序猿

sqlserver使用存储过程跟踪SQL

USE [master] GO /****** Object: StoredProcedure [dbo].[sp_perfworkload_trace_s...

1990
来自专栏大内老A

The .NET of Tomorrow

Ed Charbeneau(http://developer.telerik.com/featured/the-net-of-tomorrow/) Exciti...

30810
来自专栏Ceph对象存储方案

Luminous版本PG 分布调优

Luminous版本开始新增的balancer模块在PG分布优化方面效果非常明显,操作也非常简便,强烈推荐各位在集群上线之前进行这一操作,能够极大的提升整个集群...

3035
来自专栏转载gongluck的CSDN博客

cocos2dx 打灰机

#include "GamePlane.h" #include "PlaneSprite.h" #include "BulletNode.h" #include...

5286
来自专栏ASP.NETCore

ASP.NET Core 整合Autofac和Castle实现自动AOP拦截

除了ASP.NETCore自带的IOC容器外,我们还可以使用其他成熟的DI框架,如Autofac,StructureMap等(笔者只用过Unity,Ninjec...

674
来自专栏hbbliyong

WPF Trigger for IsSelected in a DataTemplate for ListBox items

<DataTemplate DataType="{x:Type vm:HeaderSlugViewModel}"> <vw:HeaderSlug...

4054
来自专栏闻道于事

js登录滑动验证,不滑动无法登陆

js的判断这里是根据滑块的位置进行判断,应该是用一个flag判断 <%@ page language="java" contentType="text/html...

6588

扫码关注云+社区