Android 编译

Android模拟器默认内核不支持netfilter,所以试图使用iptalbes时,会出现错误。

    1. # iptables -L  
    2. iptables -L  
    3. iptables v1.3.7: can't initialize iptables table `filter': iptables who? (do you need to insmod?)  
    4. Perhaps iptables or your kernel needs to be upgraded.  
    5. #  解决方法是重新编译一个android内核,编译的时候打开netfilter相关模块,用新内核替换原有内核即可。


      实验环境:ubuntu10.04 64bit



      下载适用模拟器的android内核代码

      1. root@ubuntu:~/android/kernel# git clone https://android.googlesource.com/kernel/goldfish.git  
      2. Initialized empty Git repository in /home/shanks/android/kernel/goldfish/.git/  
      3. remote: Counting objects: 28280, done  
      4. remote: Finding sources: 100% (6/6)  
      5. remote: Getting sizes: 100% (5/5)  
      6. remote: Compressing objects: 100% (5/5)  
      7. Receiving objects: 100% (2442118/2442118), 499.20 MiB | 772 KiB/s, done.  
      8. remote: Total 2442118 (delta 2048586), reused 2442116 (delta 2048586)  
      9. Resolving deltas: 100% (2048602/2048602), done.  

      查看可用版本
      1. root@ubuntu:~/android/kernel/goldfish# git branch -a  
      2. * master  
      3.   remotes/origin/HEAD -> origin/master  
      4.   remotes/origin/android-goldfish-2.6.29  
      5.   remotes/origin/android-goldfish-3.4  
      6.   remotes/origin/linux-goldfish-3.0-wip  
      7.   remotes/origin/master  

      下载2.6.29版本。
      1. root@ubuntu:~/android/kernel/goldfish# git checkout remotes/origin/android-goldfish-2.6.29  
      2. Checking out files: 100% (26821/26821), done.  
      3. Note: checking out 'remotes/origin/android-goldfish-2.6.29'.  

      下载完成后,设置编译所需环境变量。
      1. root@ubuntu:~/android/kernel/goldfish# export ARCH=arm  
      2. root@ubuntu:~/android/kernel/goldfish# export SUBARCH=arm  
      3. root@ubuntu:~/android/kernel/goldfish# export CROSS_COMPILE=arm-eabi-  
      4. root@ubuntu:~/android/kernel/goldfish# export PATH=<PWD>/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin:$PATH  

      运行make

      1. make goldfish_defconfig  

      接下来配置编译的模块,这个过程可能会报缺少一些必要的包,可以提前安装相关的包,也可以根据错误逐步添加。

      1. root@ubuntu:~/android/kernel/goldfish# apt-get install ia32-libs  

      下面是实验过程记录。
      1. root@ubuntu:~/android/kernel/goldfish# make menuconfig  
      2.  *** Unable to find the ncurses libraries or the  
      3.  *** required header files.  
      4.  *** 'make menuconfig' requires the ncurses libraries.  
      5.  ***   
      6.  *** Install ncurses (ncurses-devel) and try again.  
      7.  ***   
      8. make[1]: *** [scripts/kconfig/dochecklxdialog] Error 1  
      9. make: *** [menuconfig] Error 2  
      10.   
      11.   
      12. root@ubuntu:~/android/kernel/goldfish# apt-get install libncurses-dev  
      13. Reading package lists... Done  
      14. Building dependency tree         
      15. Reading state information... Done  

      再运行make menuconfig,选择相关模块。




      配置完成后,进行编译

      1. root@ubuntu:~/android/kernel/goldfish# make -j4  
      2. make: arm-eabi-gcc: Command not found  
      3.   CHK     include/linux/version.h  
      4. make[1]: `include/asm-arm/mach-types.h' is up to date.  
      5.   CHK     include/linux/utsrelease.h  
      6.   SYMLINK include/asm -> include/asm-arm  
      7.   CC      scripts/mod/empty.o  
      8. /bin/sh: arm-eabi-gcc: not found  
      9. make[2]: *** [scripts/mod/empty.o] Error 127  
      10. make[1]: *** [scripts/mod] Error 2  
      11. make: *** [scripts] Error 2  
      12.   
      13. root@ubuntu:~/android/kernel/goldfish# apt-get install lib32ncurses5-dev  
      14.   
      15. root@ubuntu:~/android/kernel/goldfish# make -j4  
      16.   CHK     include/linux/version.h  
      17.   SYMLINK include/asm -> include/asm-arm  
      18. make[1]: `include/asm-arm/mach-types.h' is up to date.  
      19.   CHK     include/linux/utsrelease.h  
      20.   CC      scripts/mod/empty.o  
      21. .../prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/bin/as: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory  
      22. make[2]: *** [scripts/mod/empty.o] Error 1  
      23. make[1]: *** [scripts/mod] Error 2  
      24. make: *** [scripts] Error 2  
      25. root@ubuntu:~/android/kernel/goldfish# apt-get install ia32-libs  
      26.   
      27.   
      28.   OBJCOPY arch/arm/boot/zImage  
      29.   Kernel: arch/arm/boot/zImage is ready  

      编译完成后,使用新内核运行模拟器。
      1. ... ools>emulator.exe -avd CM2.3 -kernel ....zImage -show-kernel -no-snapshot  
      2. serial0 console  
      3. Uncompressing Linux......................................................... done, booting the kernel.  
      4. Initializing cgroup subsys cpu  
      5. Linux version 2.6.29-gcb06bef (root@ubuntu) (gcc version 4.4.3 (GCC) ) #1 Thu Nov 8 01:35:29 PST 2012  
      6. CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00093177  
      7. CPU: VIVT data cache, VIVT instruction cache    
      问题得以解决
原文地址:https://www.cnblogs.com/liuhg/p/Android.html