1、搭建Android4.0.4编译环境;按照 http://developer.mips.com/android/android-porting-guide/ 的guide下载和编译source code;
2、在build/envsetup.sh中加入如下代码:
export TARGET_TOOLS_PRFIX=mips-linux-gnu- export USE_CCACHE=1 export TARGET_PRODUCT=sdk export TARGET_BUILD_TYPE=sdk export TARGET_ARCH_VERSION=mips32r2 export TARGET_CPU_ARCH=24kec export TARGET_CPU_TUNE=24kec export TARGET_ARCH=mips export SHOW_COMMANDS=1
export TARGET_PRODUCT=generic export TARGET_ARCH=mips export TARGET_ARCH_VARIANT=mips32r2 source build/envsetup.sh setpaths settitle
3、编译时遇到的问题:
target Dex: framework make: *** [out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/noproguard.classes-with-local.dex] Killed
UNEXPECTED TOP-LEVEL ERROR: java.lang.OutOfMemoryError: GC overhead limit exceeded at java.util.HashSet.<init>(HashSet.java:125) at com.android.dx.dex.code.StdCatchBuilder.getCatchTypes(StdCatchBuilder.java:97) at com.android.dx.dex.code.DalvCode.getCatchTypes(DalvCode.java:166) at com.android.dx.dex.file.CodeItem.addContents(CodeItem.java:126) at com.android.dx.dex.file.MixedItemSection.prepare0(MixedItemSection.java:280) at com.android.dx.dex.file.Section.prepare(Section.java:214) at com.android.dx.dex.file.DexFile.toDex0(DexFile.java:486) at com.android.dx.dex.file.DexFile.toDex(DexFile.java:196) at com.android.dx.command.dexer.Main.writeDex(Main.java:427) at com.android.dx.command.dexer.Main.run(Main.java:180) at com.android.dx.command.dexer.Main.main(Main.java:157) at com.android.dx.command.Main.main(Main.java:89) make: *** [out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/noproguard.classes-with-local.dex] Error 3
mkdir swap cd swap sudo dd if=/dev/zero of=swapfile bs=1024 count=5242880 sudo mkswap swapfile //把生成的文件转换成 Swap 文件 sudo swapon swapfile //激活 Swap 文件
4、编译成功后在/out/target/product/generics/下生成三个img:ramdisk.img 、system.img、 user.img
5、在etc/profile中添加:
export ANDROID_PRODUCT_OUT=/media/Android/android4.0/mipsandroid/out/target/product/generic export ANDROID_PRODUCT_OUT_BIN=/media/Android/android4.0/mipsandroid/out/host/linux-x86/bin export PATH=$PATH:$ANDROID_PRODUCT_OUT_BIN
./emulator -system ./data/system.img -data ./data/userdata.img -ramdisk ./data/ramdisk.img -kernel ./data/kernel-qemu -show-kernel
7、android中m,mm,mmm编译命令的区别:
m:编译所有的模块
mm:编译当前目录下的模块,当前目录下要有Android.mk文件
mmm:编译指定路径下的模块,指定路径下要有Android.mk文件
要想使用这些命令,首先需要在Android源码根目录执行. build/envsetup.sh 脚本设置环境。
在根目录下使用"make snod"重新生成system.img