必要的工具
Git
git版本需在1.5.4之上
sudo pacman -S git ;archlinux sudo apt-get install git-core ;debian
Repo
Repo是git命令的Python封装
curl http://android.git.kernel.org/repo > ~/works/bin/repo
chmod a+x ~/works/bin/repo
Python
Python版本应在2.4之上
sudo pacman -S python sudo apt-get install python
JDK 1.6
sudo pacman -S jdk sudo apt-get install sun-java5-jdk
然后在~/.bashrc中加入
export ANDROID_JAVA_HOME=$JAVA_HOME
否则在编译过程中可能会出现com.sun.javadoc找不到等错误。
获取Android源代码
1. 初始化要下载的文件列表:
mkdir -p ~/works/android cd ~/works/android repo init -u git://android.git.kernel.org/platform/manifest.git
如果想检出除master外其他分支上的代码可以用-b选项:
mkdir -p ~/works/android cd ~/works/android repo init -u git://android.git.kernel.org/platform/manifest.git -b cupcake
2. 配置git帐户
git config --global user.email "xxxxx@xxxxxxx" git config --global user.name "xxxxxx"
3. 同步文件列表:
repo sync
在第一次下载全部代码完成后,可以按模块更新子项目的代码:
repo sync project-path
其中的project-path可以在src/.repo/manifests/default.xml中找到:
<?xml version="1.0" encoding="UTF-8"?> <manifest> <remote name="korg" fetch="git://android.git.kernel.org/" review="review.source.android.com" /> <default revision="master" remote="korg" /> <project path="build" name="platform/build"> <copyfile src="core/root.mk" dest="Makefile" /> </project> <project path="kernel" name="kernel/common" revision="refs/heads/android-2.6.27" /> <project path="bionic" name="platform/bionic" /> <project path="bootable/bootloader/legacy" name="platform/bootable/bootloader/legacy" /> <project path="bootable/diskinstaller" name="platform/bootable/diskinstaller" /> <project path="bootable/recovery" name="platform/bootable/recovery" /> ... ...oject path="build" name="platform/build"> <copyfile src="core/root.mk" dest="Makefile" /> </project> <project path="kernel" name="kernel/common" revision="refs/heads/android-2.6.27" /> <project path="bionic" name="platform/bionic" /> <project path="bootable/bootloader/legacy" name="platform/bootable/bootloader/legacy" /> <project path="bootable/diskinstaller" name="platform/bootable/diskinstaller" /> <project path="bootable/recovery" name="platform/bootable/recovery" /> ... ...
编译Android源代码
编译映像
cd ~/works/android
make
映像编译成功后会在目录 ~/works/android/out/target/product/generic 下产生一些image文件
ramdisk.img system.img userdata.img android-info.txt
验证,运行这些模块:
export ANDROID_PRODUCT_OUT=/home/yunt/works/android/out/target/product/generic
cd out/host/linux-x86/bin
./emulator
错误处理
java.util.zip.ZipException: duplicate entry: hyts_Foo.c 错误
java.util.zip.ZipException: duplicate entry: hyts_Foo.c at java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:175) at java.util.jar.JarOutputStream.putNextEntry(JarOutputStream.java:92) at sun.tools.jar.Main.addFile(Main.java:713) at sun.tools.jar.Main.update(Main.java:567) at sun.tools.jar.Main.run(Main.java:202) at sun.tools.jar.Main.main(Main.java:1149) make: *** [out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/javalib.jar] Error 1 make: *** Deleting file `out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/javalib.jar'
解决办法:
这个问题是hyts_Foo.c文件重复,在根目录查找哪里重复,然后将其删除保留一个
$ find . -name hyts_Foo.c
./libcore/luni/src/test/resources/hyts_Foo.c
./libcore/support/src/test/resources/hyts_Foo.c
$ rm libcore/luni/src/test/resources/hyts_Foo.c
再次 make 即可
java.util.zip.ZipException: duplicate entry: staffNS.xml 错误
java.util.zip.ZipException: duplicate entry: staffNS.xml at java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:175) at java.util.jar.JarOutputStream.putNextEntry(JarOutputStream.java:92) at sun.tools.jar.Main.addFile(Main.java:713) at sun.tools.jar.Main.update(Main.java:567) at sun.tools.jar.Main.run(Main.java:202) at sun.tools.jar.Main.main(Main.java:1149) make: *** [out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/javalib.jar] Error 1 make: *** Deleting file `out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/javalib.jar'
解决办法同上
java.util.zip.ZipException: duplicate entry: staff2.dtd 错误
java.util.zip.ZipException: duplicate entry: staff2.dtd at java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:175) at java.util.jar.JarOutputStream.putNextEntry(JarOutputStream.java:92) at sun.tools.jar.Main.addFile(Main.java:713) at sun.tools.jar.Main.update(Main.java:567) at sun.tools.jar.Main.run(Main.java:202) at sun.tools.jar.Main.main(Main.java:1149) make: *** [out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/javalib.jar] Error 1 make: *** Deleting file `out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/javalib.jar'
同上
java.util.zip.ZipException: duplicate entry: xhtml1-strict.dtd错误
java.util.zip.ZipException: duplicate entry: xhtml1-strict.dtd at java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:175) at java.util.jar.JarOutputStream.putNextEntry(JarOutputStream.java:92) at sun.tools.jar.Main.addFile(Main.java:713) at sun.tools.jar.Main.update(Main.java:567) at sun.tools.jar.Main.run(Main.java:202) at sun.tools.jar.Main.main(Main.java:1149) make: *** [out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/javalib.jar] Error 1 make: *** Deleting file `out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/javalib.jar'
java.util.zip.ZipException: duplicate entry: staff2.xml 错误
java.util.zip.ZipException: duplicate entry: staff2.xml at java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:175) at java.util.jar.JarOutputStream.putNextEntry(JarOutputStream.java:92) at sun.tools.jar.Main.addFile(Main.java:713) at sun.tools.jar.Main.update(Main.java:567) at sun.tools.jar.Main.run(Main.java:202) at sun.tools.jar.Main.main(Main.java:1149) make: *** [out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/javalib.jar] Error 1 make: *** Deleting file `out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/javalib.jar'
java.util.zip.ZipException: duplicate entry: hc_staff.xml 错误
java.util.zip.ZipException: duplicate entry: hc_staff.xml at java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:175) at java.util.jar.JarOutputStream.putNextEntry(JarOutputStream.java:92) at sun.tools.jar.Main.addFile(Main.java:713) at sun.tools.jar.Main.update(Main.java:567) at sun.tools.jar.Main.run(Main.java:202) at sun.tools.jar.Main.main(Main.java:1149) make: *** [out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/javalib.jar] Error 1 make: *** Deleting file `out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/javalib.jar'
java.util.zip.ZipException: duplicate entry: staff.xml 错误
java.util.zip.ZipException: duplicate entry: staff.xml at java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:175) at java.util.jar.JarOutputStream.putNextEntry(JarOutputStream.java:92) at sun.tools.jar.Main.addFile(Main.java:713) at sun.tools.jar.Main.update(Main.java:567) at sun.tools.jar.Main.run(Main.java:202) at sun.tools.jar.Main.main(Main.java:1149) make: *** [out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/javalib.jar] Error 1 make: *** Deleting file `out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/javalib.jar'
java.util.zip.ZipException: duplicate entry: staff.dtd 错误
java.util.zip.ZipException: duplicate entry: staff.dtd at java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:175) at java.util.jar.JarOutputStream.putNextEntry(JarOutputStream.java:92) at sun.tools.jar.Main.addFile(Main.java:713) at sun.tools.jar.Main.update(Main.java:567) at sun.tools.jar.Main.run(Main.java:202) at sun.tools.jar.Main.main(Main.java:1149) make: *** [out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/javalib.jar] Error 1 make: *** Deleting file `out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/javalib.jar'
java.util.zip.ZipException: duplicate entry: staffNS.dtd 错误
java.util.zip.ZipException: duplicate entry: staffNS.dtd at java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:175) at java.util.jar.JarOutputStream.putNextEntry(JarOutputStream.java:92) at sun.tools.jar.Main.addFile(Main.java:713) at sun.tools.jar.Main.update(Main.java:567) at sun.tools.jar.Main.run(Main.java:202) at sun.tools.jar.Main.main(Main.java:1149) make: *** [out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/javalib.jar] Error 1 make: *** Deleting file `out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/javalib.jar'