/ 中存储网

Ubuntu 11.04 32位编译Android 4.0.3的方法及命令

2015-06-08 11:26:52 来源:中存储网

这里只是记录一些日志,难免有些错误,欢迎批评指正。

环境的建立:http://source.Android.com/source/initializing.html
源码下载参考:http://source.android.com/source/downloading.html
这里我下载4.0.3 的源码:
repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.3_r1

下载的速度看个人的网络,这里我下了一天一夜。下载好之后就可以直接make -j4编译了,编译的时候用个大概3个小时,一旦按照以上两个连接编译的话,除了内存不够之外的应该没有什么问题,这里我遇到的是就是内存不够。

我机子是VMware + Ubuntu 11.04  2G内存 2G swap,后面编译的话会遇到类似如下错误:
Install: out/host/linux-x86/framework/dx.jar
Copy: dx (out/host/linux-x86/obj/EXECUTABLES/dx_intermediates/dx)
Install: out/host/linux-x86/bin/dx
target Dex: core
make: *** [out/target/common/obj/JAVA_LIBRARIES/core_intermediates/noproguard.classes-with-local.dex] 已杀死

主要原因是内存不够,解决办法可以是增加虚拟机的内存,或者是增加swap的大小。
以下是增加swap文件方法
1.创建一个 Swap 文件。
mkdir swap
cd swap
sudo dd if=/dev/zero of=swapfile bs=1024 count=100000

出现下列提示,上面命令中的 count 即代表swap文件大小。

记录了 100000+0 的读入
记录了 100000+0 的写出
102400000 字节 (102 MB) 已复制,0.74704 秒,137 MB/秒

把生成的文件转换成 Swap 文件
sudo mkswap swapfile

Setting up swapspace version 1, size = 102395 kB
no label, UUID=09fde987-5567-498a-a60b-477e302a988b

2.激活 Swap 文件。
sudo swapon swapfile

编译好之后设置环境变量 最后用emulator 运行

www @linux:~/android-4.0.3$ export PATH=$PATH:~/android-4.0.3/out/host/linux-x86/bin
www @linux:~/android-4.0.3$ export ANDROID_PRODUCT_OUT=~/android-4.0.3/out/target/product/generic
www @linux:~/android-4.0.3$ emulator

可以使用emulator -help 查看 命令的用法,例如

emulator -verbose 可以查看运行过程。

www @linux-station:~/android-4.0.3$ emulator -verbose 
emulator: found Android build root: /home/luo/android-4.0.3 
emulator: found Android build out:  /home/luo/android-4.0.3/out/target/product/generic 
emulator: Found target ABI=armeabi-v7a, architecture=arm 
emulator: Found target API level: 15 
emulator: using core hw config path: /home/luo/android-4.0.3/out/target/product/generic/hardware-qemu.ini 
emulator: found skin-specific hardware.ini: /home/luo/android-4.0.3/development/tools/emulator/skins/HVGA/hardware.ini 
emulator: autoconfig: -skin HVGA 
emulator: autoconfig: -skindir /home/luo/android-4.0.3/development/tools/emulator/skins 
emulator: writing default keyset file to /home/luo/.android/default.keyset 
emulator: trying to load skin file '/home/luo/android-4.0.3/development/tools/emulator/skins/HVGA/layout' 
emulator: skin network speed: 'full' 
emulator: skin network delay: 'none' 
emulator: Found target ABI=armeabi-v7a 
emulator: autoconfig: -kernel /home/luo/android-4.0.3/prebuilt/android-arm/kernel/kernel-qemu-armv7 
emulator: autoconfig: -ramdisk /home/luo/android-4.0.3/out/target/product/generic/ramdisk.img 
emulator: autoconfig: -sysdir /home/luo/android-4.0.3/out/target/product/generic 
emulator: Using initial system image: /home/luo/android-4.0.3/out/target/product/generic/system.img 
emulator: WARNING: system partition size adjusted to match image file (166 MB > 66 MB) 

emulator: autoconfig: -data /home/luo/android-4.0.3/out/target/product/generic/userdata-qemu.img 
emulator: autoconfig: -initdata /home/luo/android-4.0.3/out/target/product/generic/userdata.img 
emulator: Physical RAM size: 512MB 

emulator: Auto-config: -qemu -cpu cortex-a8 
Content of hardware configuration file: 
hw.cpu.arch = arm 
hw.cpu.model = cortex-a8 
hw.ramSize = 512 
hw.touchScreen = yes 
hw.mainKeys = yes 
hw.trackBall = yes 
hw.keyboard = yes 
hw.keyboard.lid = no 
hw.keyboard.charmap = qwerty2 
hw.dPad = yes 
hw.gsmModem = yes 
hw.camera = no 
hw.camera.maxHorizontalPixels = 640 
hw.camera.maxVerticalPixels = 480 
hw.gps = yes 
hw.battery = yes 
hw.accelerometer = yes 
hw.audioInput = yes 
hw.audioOutput = yes 
hw.sdCard = yes 
hw.sdCard.path =  
disk.cachePartition = yes 
disk.cachePartition.path =  
disk.cachePartition.size = 66m 
hw.lcd.width = 320 
hw.lcd.height = 480 
hw.lcd.depth = 16 
hw.lcd.density = 160 
hw.lcd.backlight = yes 
hw.gpu.enabled = no 
hw.fakeCamera = back 
hw.webcam.count = 6 
hw.webcam.0.name = webcam0 
hw.webcam.1.name = webcam1 
hw.webcam.2.name = webcam2 
hw.webcam.3.name = webcam3 
hw.webcam.4.name = webcam4 
hw.webcam.5.name = webcam5 
hw.webcam.0.direction = front 
hw.webcam.1.direction = back 
hw.webcam.2.direction = front 
hw.webcam.3.direction = front 
hw.webcam.4.direction = front 
hw.webcam.5.direction = front 
vm.heapSize = 48 
hw.sensors.proximity = yes 
kernel.path = /home/luo/android-4.0.3/prebuilt/android-arm/kernel/kernel-qemu-armv7 
kernel.parameters =  android.checkjni=1 
disk.ramdisk.path = /home/luo/android-4.0.3/out/target/product/generic/ramdisk.img 
disk.systemPartition.initPath = /home/luo/android-4.0.3/out/target/product/generic/system.img 
disk.systemPartition.size = 166m 
disk.dataPartition.path = /home/luo/android-4.0.3/out/target/product/generic/userdata-qemu.img 
disk.dataPartition.size = 66m 
disk.snapStorage.path =  
avd.name = <build> 

QEMU options list: 
emulator: argv[00] = "/home/luo/android-4.0.3/out/host/linux-x86/bin/emulator-arm" 
emulator: argv[01] = "-android-hw" 
emulator: argv[02] = "/tmp/android-luo/emulator-afcKDX" 
Concatenated QEMU options: 
 /home/luo/android-4.0.3/out/host/linux-x86/bin/emulator-arm -android-hw /tmp/android-luo/emulator-afcKDX 
emulator: registered 'boot-properties' qemud service 
emulator: nand_add_dev: system,size=0xa600000,initfile=/home/luo/android-4.0.3/out/target/product/generic/system.img 
emulator: mapping 'system' NAND image to /tmp/android-luo/emulator-eyG1eN 
emulator: rounding devsize up to a full eraseunit, now a608000 

WARNING: Data partition already in use. Changes will not persist! 
emulator: nand_add_dev: userdata,size=0x4200000 
emulator: mapping 'userdata' NAND image to /tmp/android-luo/emulator-RO2LHH 
emulator: registered 'boot-properties' qemud service 
emulator: Adding boot property: 'dalvik.vm.heapsize' = '48m' 
emulator: Adding boot property: 'qemu.sf.lcd_density' = '160' 
emulator: Adding boot property: 'qemu.hw.mainkeys' = '1' 
emulator: Adding boot property: 'qemu.sf.fake_camera' = 'back' 
emulator: nand_add_dev: cache,size=0x4200000 
emulator: mapping 'cache' NAND image to /tmp/android-luo/emulator-wX6JvG 
emulator: Kernel parameters: qemu.gles=0 qemu=1 console=ttyS0 android.qemud=ttyS1 android.checkjni=1 ndns=1 
emulator: Trace file name is not set 

emulator: autoconfig: -scale 1 
emulator: control console listening on port 5556, ADB on port 5557 
emulator: can't connect to ADB server: Connection refused 
emulator: ping program: /home/luo/android-4.0.3/out/host/linux-x86/bin/ddms 
emulator: ping command: /home/luo/android-4.0.3/out/host/linux-x86/bin/ddms ping emulator 14.0 
goldfish_fb_get_pixel_format:167: display surface,pixel format: 
bits/pixel:  16 
bytes/pixel: 2 
depth: 16 
red:   bits=5 mask=0xf800 shift=11 max=0x1f 
green: bits=6 mask=0x7e0 shift=5 max=0x3f 
blue:  bits=5 mask=0x1f shift=0 max=0x1f