博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android 源码编译 文件系统制作
阅读量:4047 次
发布时间:2019-05-25

本文共 11736 字,大约阅读时间需要 39 分钟。

Android Source Code Download

  TOP Website
  android 的最新源代码下载的官方网站是:http://source.android.com
  源代码的下载说明页面是:http://source.android.com/download (现在貌似用还用不了)
  现在的网站是http://git.android.com
  TOP Create Directory
  在HOME(/home/justin)目录下创建如下目录结构:
  /home/justin/android :
  总计 36
  drwxr-xr-x 7 justin justin 4096 01-15 10:34 .
  drwxr-xr-x 58 justin justin 12288 01-15 10:39 ..
  drwxr-xr-x 2 justin justin 4096 01-15 10:34 applications
  drwxr-xr-x 2 justin justin 4096 01-15 10:33 downloads
  drwxr-xr-x 2 justin justin 4096 01-15 12:34 bin
  drwxr-xr-x 2 justin justin 4096 01-15 10:33 sdk
  drwxr-xr-x 2 justin justin 4096 01-15 10:33 src
  drwxr-xr-x 2 justin justin 4096 01-15 10:34 tools
  将该目录添加到PATH环境变量:
  export PATH=$HOME/android/bin:$PATH
  如果需要反复使用,需要将这一行加入~/.bashrc启动脚本中
  TOP Donwload Tool Chain
  TOP Git
  Git的版本在1.5.4之上
  sudo apt-get install git-core
  TOP Proxy
  安装代理软件:
  apt-get install connect-proxy
  Repo
  repo是包装了git命令的python
  脚本:
  curl http://android.git.kernel.org/repo > ~/android/bin/repo
  网关内部需要设置curl代理
  假设网段的(http)代理为:wwwgate.freeshell.net:8080
  curl --proxy wwwgate.freeshell.net:8080 http://android.git.kernel.org/repo > ~/android/bin/repo
  加上可执行权限
  chmod a+x ~/android/bin/repo
  Python
  Python的版本在2.4之上
  sudo apt-get install python
  JDK 1.6
  在下列地址下载: http://java.sun.com/javase/downloads 解压得到如下文件: ~/android /downloads/jdk-6u11-linux-i586.bin
  cd ~/android/downloads
  chmode a+x jdk-6u11-linux-i586.bin
  运行这个可执行文件, 将生成的目录jdk1.6.0_11拷贝到/usr/local/下
  将下列环境变量加入~/.bashrc:
  export PATH=/usr/local/jdk1.6.0_11/bin:$PATH
  export JAVA_HOME=/usr/local/jdk1.6.0_11
  export ANDROID_JAVA_HOME=$JAVA_HOME
  tools
  sudo apt-get install gcc g++
  sudo apt-get install flex bison gperf libsdl1.2-dev libesd0-dev libwxgtk2.6-dev /
  build-essential zip curl libncurses5-dev zlib1g-dev valgrind libreadline5-dev
  如果因为缺少X11/Xatom.h和X11/Xlib.h导致的build失败,
  可以安装如下包:
  sudo apt-get install x11proto-core-dev # provides Xatom.h
  sudo apt-get install libx11-dev # provides Xlib.h
  交叉编译环境
  android emulator 默认的目标代码是arm7的代码。如果需要将目标代码移植到其他版本的arm平台上去,需要重新配置相应的交叉编译环境。
  TOP 下载Android平台源代码
  1. 初始化要下载的文件列表:
  cd ~/android/src
  repo init -u git://android.git.kernel.org/platform/manifest.git
  如果想检出除master外其他分支上的代码可以用-b选项:
  cd ~/android/src
  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="http://blog.soso.com/qz.q/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" />
  ... ...
  在网关内部使用需要设置代理:
  新建如下文件: #!/bin/sh
  # /home/justin/android/bin/socks-gw.sh

# This script connects to a HTTP proxy using connect.c

  connect -H wwwgate.freeshell.net:8080 #!/bin/sh
  # /home/justin/android/bin/socks-ssh.sh
  ssh -o ProxyCommand="/home/justin/android/bin/socks-gw.sh %h %p" $@
  增加这两个文件的可执行权限:
  chmod a+x /home/justin/android/bin/socks-ssh.sh
  chmod a+x /home/justin/android/bin/socks-gw.sh
  可以将所有代理的环境变量放在:
  #!/bin/sh
  # /home/justin/proxy.sh
  # http proxy setting
  export HTTP_PROXY=http://wwwgate.freeshell.net:8080
  export http_proxy=$HTTP_PROXY
  # set git to use ssh over http proxy
  export GIT_SSH="/home/justin/android/bin/socks-ssh.sh"
  export GIT_PROXY_COMMAND="/home/justin/android/bin/socks- gw.sh"
  需要的时候运行:
  . ~/proxy.sh
  编译Android平台以及SDK
  完全编译
  编译映像
  cd ~/android/src
  make
  映像编译成功后会在目录~/android/src/out/target/product/generic
  下产生一些image文件
  ramdisk.img system.img userdata.img android -info.txt
  验证,运行这些模块:
  export ANDROID_PRODUCT_OUT=/home/justin/android/src/out/t arget/product/generic
  cd out/host/linux-x86/bin
  ./emulator
  此时可能出现如下错误
  SDL init failure, reason is: No available video device
  需要设置下图形server
  # export DISPLAY=:0
  SDK编译
  在做完一次完全编译后,就可以build SDK了。
  make sdk
  注意:如果需要build SDK,需要安装sun-java5-jdk, 而不是sun-java6-jdk,否则会出现如下错误:
  build/core/product_config.mk:207: WARNING: adding test OTA key
  ============================================
  TARGET_PRODUCT=generic
  TARGET_BUILD_VARIANT=eng
  TARGET_BUILD_TYPE=release
  TARGET_ARCH=arm
  HOST_ARCH=x86
  HOST_OS=linux
  HOST_BUILD_TYPE=release
  BUILD_ID=
  ============================================
  Combining NOTICE files: out/target/product/generic/obj/NOTICE.txt
  Finding NOTICE files: out/host/linux-x86/obj/NOTICE_FILES/hash-timestamp
  Combining NOTICE files: out/host/linux-x86/obj/NOTICE.txt
  out/target/product/generic/generic-img-eng.justin. zip
  SDK buildinfo: out/target/product/generic/sdk/sdk-build.prop
  Docs droiddoc: out/target/common/docs/dx
  此时,可以考虑重新安装sun jdk5, 或者直接从http://java.sun.com/javase/downloads
  下载到~/android
  /downloads/jdk-1_5_0_17-linux-i586.bin
  sudo apt-get install sun-java5-jdk
  并设置相应的.bashrc命令。
  sdk编译成功后会在~/android /src /out/host/linux-x86/sdk/ 生成sdk的文件目录和压缩包:
  android -sdk_eng.justin_linux-x86
  android -sdk_eng.justin_linux-x86.zip
  并在~/android /src /out/target/product/generic(generic是默认的产品名)下打包所有的映像文件:
  generic-img-eng.justin.zip
  生成的SDK目录结构为:
  /home/justin/android/src/out/host/linux-x86/sdk/an droid-sdk_eng.justin_linux-x86:
  总计 32
  drwxrwx--- 6 justin justin 4096 02-13 17:06 .
  drwxr-x--- 3 justin justin 4096 02-13 17:09 ..
  drwxrwx--- 2 justin justin 4096 02-13 17:06 add-ons
  drwxrwx--- 14 justin justin 4096 02-13 17:06 docs
  -rw-rw---- 1 justin justin 172 02-13 17:08 documentation.html
  drwxrwx--- 3 justin justin 4096 02-13 17:06 platforms
  -rw-rw---- 1 justin justin 225 02-13 17:08 RELEASE_NOTES.txt
  drwxrwx--- 3 justin justin 4096 02-13 17:08 tools
  安装生成的SDK只需要在.bashrc中增加:
  export PATH=$PATH:/home/justin/android/src/out/host/linux -x86/sdk/android-sdk_eng.justin_linux-x86/tools
  为了使用方便,将生成的SDK目录链结至~/android
  /sdk:
  ln -sf /home/justin/android/src/out/host/linux-x86/sdk/an droid-sdk_eng.justin_linux-x86/tools /
  ~/android/sdk
  模块编译
  在src目录执行:
  cd ~/android/src
  . build/envsetup.sh
  envsetup.sh 提供了一些的bash函数定义,当运行了envsetup.sh后就可以使用help
  命令来查看:
  help
  得到这些命令的帮助信息:
  Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
  - 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.
  Look at the source to view more functions. The complete list is:
  add_lunch_combo cgrep check_product check_variant choosecombo chooseproduct choosetype choosevariant croot findmakefile gd
  bclient get_abs_build_var getbugreports get_build_var getprebuilt gettop help isviewserverstarted jgrep lunch m mm mmm pid
  printconfig print_lunch_menu resgrep runhat runtest setpaths set_sequence_number set_stuff_for_environment settitle smoke
  test startviewserver stopviewserver tapas tracedmdump
  其中对模块的编译有帮助的是tapas、m、mm、mmm这几个命令。
  1.tapas - 以交互方式设置build环境,以下是运行效果:
  tapas
  第一步,选择目标设备:
  Build for the simulator or the device?
  1. Device
  2. Simulator
  Which would you like? [1]
  第二步,选择目标代码格式:Build type choices are:
  1. release
  2. debug
  Which would you like? [1]
  第三步,选择产品平台:
  Product choices are:
  1. emulator
  2. generic
  3. sim
  You can also type the name of a product if you know it.
  Which would you like? [generic]
  第四步,在选用参数下构建平台。
  2. 独立模块的构件命令
  * 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.
  其中mmm后面要跟模块的根目录,不是所有的目录下都有子模块,那些含有Android.mk文件目录才是模块的根目录,模块名可以从 Android.mk的LOCAL_MODULE或者LOCAL_PACKAGE_NAME变量中得到。
  单独编译某模块,需要在mmm后面指定模块路径,例如编译application中的Contacts:
  mmm packages/apps/Contacts/
  或者在src目录下直接运行make module name :
  cd ~/android/src
  make Contacts
  TOP 增量编译的步骤
  1. 修改代码
  2. 编译所修改的代码所在模块,例如:
  cd ~/android/src
  mmm packages/apps/Contacts
  3. 在~/android /src 中运行:
  cd ~/android/src
  make snod
  该命令生成一个新的系统映像system.img
  4.将这个系统映像拷贝至sdk下:
  cd ~/android/src
  cp out/target/product/generic/system.img /
  out/host/linux-x86/sdk/android-sdk_eng.justin_linu x-x86/tools/lib/images/
  5. 删除程序遗留的数据:
  out/host/linux-x86/sdk/android-sdk_eng.justin_linu x-x86/tools/emulator -wipe-data
  制作文件系统
  Usually the Android uses YAFFS as rootfs and uses the mtd device as storage media, the bad blocks in the mtd device seldom cause YAFFS file system to work abnormally. if the Android uses NFS as the rootfs, there will not exist such problem. So here is the solution to use NFS as the rootfs of Android.
  1. Setup host machine as NFS server (I will use ubuntu 8.0.4 as an example.).
  $ sudo apt-get install nfs-kernel-server portmap
  $ sudo mkdir /nfsroot
  $ sudo vim /etc/exports
  Add one line in /etc/exports,
  /nfsroot 192.168.1.101(rw,no_root_squash ,sync)
  Then restart NFS server.
  $ sudo /etc/init.d/nfs-kernel-server restart Here setups an NFS server which exports /nfsroot directory only to 192.168.1.101(Which is the default IP address of Android eth0).
  2. Build a Linux kernel image to use NFS as rootfs.
  $make menuconfig
  Modify the default setup. In "general setup" section, uncheck the "initial RAM filesystem and RAM disk(initramfs/initrd) support". In "file systems" section, check the "Network File Systems" and mark it as kernel built-in. In "boot options" section, add the kernel parameter "root=/dev/nfs nfsroot=192.168.1.100:/nfsroot init=/init ". 192.168.1.100 is the IP address of host machine running NFS server.
  3. Modify init program.
  To make log system work, in the device/system/init modify the device.c by change the statement '!strncmp(uevent->path,"/class/misc/",12) && !strncmp(name, "log_", 4) to '!strncmp(name, "log_", 4) '.
  4. Modify init.rc config file.
  Comment out below statements
  mount rootfs rootfs /ro remount
  mount yaffs mtd@system /system
  mount yaffs2 mtd@system /system ro remout 
 mount yaffs2 mtd@userdata /data nosuid nodev
  mount yaffs2 mtd@cache /cache nosuid nodev
  5. Add the user id and group id used by android on the NFS server.
  Android does not use /ect/passwd file to record the user name and user id, it uses a fixed method to map the user name to user id through the head file device/include/private/android_filesystem_config.h , e.g. the user "system" has the user id of 1000.
  So to correctly set the file ownership(owner and group), the NFS server should have these users with correct user IDs. Such as system(1000). For ubuntu, you can call like this.
  $sudo userdd -u 1000 android_system
  6. This step is not necessary. It only allows you to display a user name in the develop machine. 6. Prepare the rootfs.
  Assume the built output of device lies in device/out/target/product/***/, which is called $OUTPUTDIR later. Do the follwings:
  $cp -rf $OUTPUTDIR/root/* /nfsroot
  $cp -rf $OUTPUTDIR/system /nfsroot
  $cp -rf $OUTPUTDIR/data /nfsroo
  参考
http://mmmyddd.freeshell.net/wiki/android/build.ht ml#top

转载地址:http://vakci.baihongyu.com/

你可能感兴趣的文章
解决跨网场景下,CAS重定向无法登录的问题(无需修改现有代码)
查看>>
java反编译命令
查看>>
activemq依赖包获取
查看>>
概念区别
查看>>
final 的作用
查看>>
在Idea中使用Eclipse编译器
查看>>
idea讲web项目部署到tomcat,热部署
查看>>
Idea下安装Lombok插件
查看>>
zookeeper
查看>>
Idea导入的工程看不到src等代码
查看>>
技术栈
查看>>
Jenkins中shell-script执行报错sh: line 2: npm: command not found
查看>>
8.X版本的node打包时,gulp命令报错 require.extensions.hasownproperty
查看>>
Jenkins 启动命令
查看>>
Maven项目版本继承 – 我必须指定父版本?
查看>>
通过C++反射实现C++与任意脚本(lua、js等)的交互(二)
查看>>
利用清华镜像站解决pip超时问题
查看>>
[leetcode BY python]1两数之和
查看>>
微信小程序开发全线记录
查看>>
PTA:一元多项式的加乘运算
查看>>