`

Android编译生成系统-译文

阅读更多

生成 4.0.1 系统

下边就是生成系统的具体命令:

 

初始化

envsetup.sh 脚本初始化环境。 也可以用 ”.” 来代替 source

$ source build/envsetup.sh 

or

$ . build/envsetup.sh

 

选择一个目标

选择 build 哪个目标使用命令 lunch ,具体的配置可以参数设置,例如

$ lunch full-eng

上边给的例子就是 build 一个全部可以调试的 emulator

如果你直接使用 lunch   没有参数的话,会弹出选择目标菜单。

所有的目标可以从 BUILD-BUILDTYPE 中查阅到, BUILD 可以为下边的几个:

Build name

Device

Notes

full

emulator

fully configured with all languages, apps, input methods

full_maguro

maguro

full  build running on Galaxy Nexus GSM/HSPA+ ("maguro")

full_panda

panda

full  build running on PandaBoard ("panda")

BUILDTYPE 为下边的几个:

Buildtype

Use

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

 

开始 Build 代码

全部 编译 使用 make 命令, GNU make 通过 -jN   参数可以选择全力发挥 cpu 的功能,一般 N 1 2 倍硬件的线程数,例如 dual-E5520 machine (2 CPUs, 4 cores per CPU, 2 threads per core) 如果要最快的 Build ,我们可以使用命令 make -j16     make -j32

$ make -j4

 

运行它

你不仅可以在 emulator 上运行,也可以刷到设备上(lunch的参数不同)。

刷到设备中

为了刷到设备中,你必须使用 fastboot 工具,如果你 Build 成功,这个会自动加到你的路径中,可以直接使用,在 boot 下通过合适的 key 手动设置你的设备为 fastboot 模式,亦或者你可以通过 shell 命令。

$ adb reboot bootloader 

只要设备进入 fastboot 模式,就可以运行

$ fastboot flashall -w

这个 -w 参数是清除 你设备 /data 下的数据的。第一次刷的时候尽量使用这个参数,以后再刷就没有必要清除了。

在设备上运行

这个 emulator 命令自动加到你的 path 路径中了,可以直接运行

$ emulator
 

使用 ccache

ccache 就是 C/C++ 编译器缓存,它能够使 Build 的更快,在源码根目录下进行操作

$ export USE_CCACHE=1
$ export CCACHE_DIR=/<path_of_your_choice>/.ccache
$ prebuilt/linux-x86/ccache/ccache -M 20G

通过下边命令,你可以查看 ccache 的使用情况

$ watch -n1 -d prebuilt/linux-x86/ccache/ccache -s

 如果在 OSX ,你应该替换 linux-x86     darwin-x86

 

一般 Build 遇到的问题

错误的 Java 版本

如果你试图使用 JDK1.6 Build froyo 或之前版本,亦或者你试图使用 JDK1.5 Build gingerbread 或之后版本, make 的时候会报下边错误。

************************************************************
You are attempting to build with the incorrect version
of java.

Your version is: WRONG_VERSION.
The correct version is: RIGHT_VERSION.

Please follow the machine setup instructions at
    http://source.android.com/download
************************************************************

这个可能是因为下边原因导致的

错误的使用 JDK 的版本, Building 源码需要版本对应的 Sun JDK 5 or 6

另一个 JDK 也在你的 path 路径中,使用的是另一个 JDK ,这种情况你可以使用下边的命令删除那个没有用的 JDK

$ export PATH=${PATH/\/path\/to\/jdk\/dir:/}

 

Python 版本 3

Repo 的使用使用搞的是 Python 2.x 不兼容 Python 3 ,如果想用 repo 那就安装 Python 2.x:

$ apt-get install python

 

没有 USB 权限

在大多 Linux 系统,普通的用户默认是没有访问 USB 端口的权限的,你可能会遇到没有权限的错误信息,下边配置下 USB 的访问权限。

如果 adb 正在运行并且不能连接设备,你可以使用   adb kill-server ,这样 adb 会根据配置文件重新运行的。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics