创建工程目录:
1 $ mkdir Android
2 $ cd android
repo初始化
1 $ repo init -u git://android.git.kernel.org/platform/manifest.git
在此过程中需要输入名字和email地址。初始化成功后,会显示:
repo initialized in /android
在~/android下会有一个.repo的隐藏目录。
5)同步源代码1 $ repo sync
这一步要很久很久
6)编译android源码,并得到~/android/out目录
1 $ cd ~/andoird
2 $ make
这一过程很久,我是看了部一个多小时的电影之后编译完成的,具体看电脑配置了~
7)在模拟器上运行编译好的android
编译好android之后,
emulator在~/android/out/host/linux-x86/bin 下,
ramdisk.img,system.img和userdata.img则在~/android/out/target/product /generic下1 $ cd ~/android/out/host/linux-x86/bin
增加环境变量
1 $ gvim ~/.bashrc
在.bashrc中新增环境变量,如下
1 #java 程序开发/运行的一些环境变量
2 export ANDROID_PRODUCT_OUT=~/android/out/target/product/generic
3 ANDROID_PRODUCT_OUT_BIN=~/android/out/host/linux-x86/bin
4 export PATH=${PATH}:${ANDROID_PRODUCT_OUT_BIN}:${ANDROID_PRODUCT_OUT};
最后,同步这些变化:
1 $ source ~/.bashrc
2 $ cd ~/android/out/target/product/generic
3 $ emulator -system system.img -data userdata.img -ramdisk ramdisk.img
最后进入android桌面,就说明成功了。
8)编译模块
android中的一个应用程序可以单独编译,编译后要重新生成system.img
在源码目录下执行1 $ . build/envsetup.sh (.后面有空格)
就多出一些命令:
- croot: Changes directory to the top of the tree.
- m: Makes from the top of the tree.
- mm: Builds all of the modules in the current directory.
- mmm: Builds all of the modules in the supplied directories.
- cgrep: Greps on all local C/C++ files.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir: Go to the directory containing a file.
可以加—help查看用法
我们可以使用mmm来编译指定目录的模块,如编译联系人:1 $ mmm packages/apps/Contacts/
编完之后生成两个文件:
out/target/product/generic/data/app/ContactsTests.apk
out/target/product/generic/system/app/Contacts.apk
可以使用
1 $ make snod
重新生成system.img,再运行模拟器