zoukankan      html  css  js  c++  java
  • 编译Android源码

    通过参考网上的相关资料,我编译Android源码的步骤如下:

    • 1 我的系统是Ubuntu 8.04
    • 2 系统上必须安装以下工具(摘自网上的资料):
       
       sudo apt-get install build-essential
       sudo apt-get install make
       sudo apt-get install gcc
       sudo apt-get install g++
       sudo apt-get install libc6-dev
       
       sudo apt-get install flex
       sudo apt-get install bison
       sudo apt-get install patch
       sudo apt-get install texinfo
       sudo apt-get install libncurses-dev
       
       sudo apt-get install git-core gnupg  //(gnupg系统可能已自带)
       sudo apt-get install flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl
       sudo apt-get install ncurses-dev 
       sudo apt-get install zlib1g-dev
       sudo apt-get install valgrind(可选,有21M大,我觉得一般人是用不到的)
       sudo apt-get install python2.5 (实际上不用装,Ubuntu 8.04 已经自带)
       sudo apt-get install sun-java5-jdk
       
       注意:
       a. 不要用 sun-java6-jdk, 不然在make sdk, 具体来说是make doc这一步中, 遇到这个错误:
         Docs droiddoc: out/target/common/docs/dx
         javadoc: error - In doclet class DroidDoc, method start has thrown an
         exception java.lang.reflect.InvocationTargetException
         com.sun.tools.javac.code.Symbol$CompletionFailure: class file for
         sun.util.resources.OpenListResourceBundle not found
       b. 网上资料说需要设置环境变量, 但我并没有设置:
        export ANDROID_JAVA_HOME=$JAVA_HOME
        
       c. 网上并没有提及要安装ncurses-dev, 但安装之前我编译过程中会出现编译错误.
       
    • 3 建立android源码的存放目录
       $ mkdir ~/open_src
       $ mkdir ~/open_src/android
       $ cd ~/open_src/android
       $ mkdir bi
    • 4 下载repo脚本,放到~/open_src/android/bin目录下,加上可执行权

              $ curl http://android.git.kernel.org/repo > repo
              $ sudo mv repo ~/open_src/android/bin
              $ sudo chmod a+x ~/open_src/android/bin/repo 

    • 5 在源码存放目录android中执行
       $ ~/open_src/android/bin/repo init -u git://android.git.kernel.org/platform/manifest.git
       //中间会提示输入电子邮件什么的, 如果你打算要提交patch的话,用google accounts注册过的邮箱
       
    • 6 在android目录中执行repo sync就可以开始下载源码了.
       我们也可以从其他地方把源码复制到android目录, 而我正是这么做的.
    • 7 编译源码, 并得到~/open_src/android/out 目录
       在命令行执行make命令:
       $make
       这 是一个很漫长的过程, 等吧......
    • 8 测试运行
       8.1 先设置环境变量:
        打开~/.bashrc文件, 并在最后添加下面两行:
        export PATH=$PATH:~/open_src/android/out/host/linux-x86/bin
        export ANDROID_PRODUCT_OUT=~/open_src/android/out/target/product/generic
       
       8.2 运行模拟器:
        emulator --debug-init -skin QVGA-L  //可能会提示unknown option: --debug-init, 去掉--debug-init即可
        或者直接执行emulator, 这样使用的是默认的皮肤
       
       如 果最后能进入到系统并看到一个大时钟, 说明就大功告成了.
       
       
    • 9 后续编译:

               先在android目录下执行
               $ . build/envsetup.sh
               然 后你就会多出几个可用的命令。在改了Contacts联系人项目后,可以简单的执行一下命令来单独编译这个部分:
               $mmm packages/apps/Contacts/
              为了可以直接测试改动,需要生成新的system.img,在android目录下执行:
               $ make snod
              当然,如果你改动的是emulator或者其它外围相关的,而非系统内部的东西,就不只是要重新生成system.img了

    • 以下是编译成功后的最后一些输出:
      Install: out/target/product/generic/system/xbin/scp
      Notice file: system/extras/showmap/NOTICE -- out/target/product/generic/obj/NOTICE_FILES/src//system/xbin/showmap.txt
      Install: out/target/product/generic/system/xbin/showmap
      Notice file: system/extras/showslab/NOTICE -- out/target/product/generic/obj/NOTICE_FILES/src//system/xbin/showslab.txt
      Install: out/target/product/generic/system/xbin/showslab
      Notice file: external/sqlite/dist/NOTICE -- out/target/product/generic/obj/NOTICE_FILES/src//system/xbin/sqlite3.txt
      Install: out/target/product/generic/system/xbin/sqlite3
      Notice file: external/dropbear/NOTICE -- out/target/product/generic/obj/NOTICE_FILES/src//system/xbin/ssh.txt
      Install: out/target/product/generic/system/xbin/ssh
      Install: out/target/product/generic/system/xbin/strace
      Notice file: system/extras/su/NOTICE -- out/target/product/generic/obj/NOTICE_FILES/src//system/xbin/su.txt
      Install: out/target/product/generic/system/xbin/su
      Install: out/target/product/generic/system/xbin/timeinfo
      Copy: out/target/product/generic/system/etc/apns-conf.xml
      Copying: out/target/product/generic/obj/NOTICE_FILES/src/kernel.txt
      Finding NOTICE files: out/target/product/generic/obj/NOTICE_FILES/hash-timestamp
      Combining NOTICE files: out/target/product/generic/obj/NOTICE.html
      gzip -c out/target/product/generic/obj/NOTICE.html > out/target/product/generic/obj/NOTICE.html.gz
      zip -qj out/target/product/generic/system/etc/security/otacerts.zip build/target/product/security/testkey.x509.pem
      Generated: (out/target/product/generic/android-info.txt)
      Target system fs image: out/target/product/generic/obj/PACKAGING/systemimage_unopt_intermediates/system.img
      Install system fs image: out/target/product/generic/system.img
      Target ram disk: out/target/product/generic/ramdisk.img
      Target userdata fs image: out/target/product/generic/userdata.img

  • 相关阅读:
    openlayers5-webpack 入门开发系列一初探篇(附源码下载)
    leaflet-webpack 入门开发系列二加载不同在线地图切换显示(附源码下载)
    Cesium-空间分析之通视分析(附源码下载)
    Geoserver2.15.1 配置自带 GeoWebCache 插件发布 ArcGIS Server 瓦片(附配置好的 Geoserver2.15.1 下载)
    leaflet-webpack 入门开发系列一初探篇(附源码下载)
    maven学习(上)- 基本入门用法
    Java面试11|Maven与Git
    必须学会git和maven
    Git 安装和使用教程
    用git,clone依赖的库
  • 原文地址:https://www.cnblogs.com/AlexCheng/p/2120212.html
Copyright © 2011-2022 走看看