编译SDK

编译SDK可以得到与源码同步的SDK,还会生成一些tools,在源码根目录下:

[plain] view plain copy
  1. $sudomakePRODUCT-sdk-sdk

编译生成的SDK在out/host/linux-x86/SDK下。之后如果在ubuntu下使用eclipse进行开发,可以使用你编译的SDK。

下面就在模拟器中运行镜像,建议切到root用户下,首先配置几个环境变量,将自己编译的SDK设为优先级最高,在源码根目录下执行:

[plain] view plain copy
  1. $update-alternatives--install/usr/bin/AndroidSDKAndroidSDK./out/host/linux-x86/sdk/android-sdk_eng.root_linux-x86255

这样会在/etc/alternatives下生成一个指向该SDK目录的软连接AndroidSDK,这个目录主要存放一些系统默认打开的程序的信息和配置。那么/usr/bin/AndroidSDK就指向这个软连接。接着执行:

[plain] view plain copy
  1. $gedit~/.bashrc

在文件末尾添加:

[plain] view plain copy
  1. exportANDROID_SDK_HOME=/usr/bin/AndroidSDK
  2. exportPATH=$ANDROID_SDK_HOME/tools:$PATH

首先你需要设置一下emulator工具的目录之类的,这个不细说了,

要在.bashrc中新增环境变量,如下

ANDROID_PRODUCT_OUT=~/android/out/target/product/generic

ANDROID_PRODUCT_OUT_BIN=~/android/out/host/linux-x86/bin

这里是设置你的输出文件的位置和bin工具目录,不用多解释吧?

然后在命令行输入:

export PATH=${PATH}:${ANDROID_PRODUCT_OUT_BIN}:${ANDROID_PRODUCT_OUT};

上面是导入了相关的配置,然后使之生效。

source ~/.bashrc

接着切换到输出的system文件夹

cd~/android/out/target/product/generic

然后来创建模拟器

emulator -system system.img -data userdata.img -ramdisk ramdisk.img

如果你运气够好的话,也许现在已经在运行了,不过我运气明显不够好。

提示一:

emulator: ERROR: You did not specify a virtual device name, and the system
directory could not be found.

If you are an Android SDK user, please use ‘@<name>’ or ‘-avd <name>’
to start a given virtual device (see -help-avd for details).

Otherwise, follow the instructions in -help-disk-images to start the emulator

既然人家提示了,那就按照步骤走吧,输入命令:

emulator -help-avd

接着提示如下:

use ‘-avd <name>’ to start the emulator program with a given Android
Virtual Device (a.k.a. AVD), where <name> must correspond to the name
of one of the existing AVDs available on your host machine.

See -help-virtual-device to learn how to create/list/manage AVDs.

As a special convenience, using ‘@<name>’ is equivalent to using
‘-avd <name>’.

跟着提示继续走,输入命令:

emulator -help-virtual-device

又是提示了:

An Android Virtual Device (AVD) models a single virtual
device running the Android platform that has, at least, its own
kernel, system image and data partition.

Only one emulator process can run a given AVD at a time, but
you can create several AVDs and run them concurrently.

You can invoke a given AVD at startup using either ‘-avd <name>’
or ‘@<name>’, both forms being equivalent. For example, to launch
the AVD named ‘foo’, type:

emulator @foo

The ‘android’ helper tool can be used to manage virtual devices.
For example:

android create avd -n <name> -t 1 # creates a new virtual device.
android list avd # list all virtual devices available.

Try ‘android –help’ for more commands.

Each AVD really corresponds to a content directory which stores
persistent and writable disk images as well as configuration files.
Each AVD must be created against an existing SDK platform or add-on.
For more information on this topic, see -help-sdk-images.

SPECIAL NOTE: in the case where you are *not* using the emulator
with the Android SDK, but with the Android build system, you will
need to define the ANDROID_PRODUCT_OUT variable in your environment.
See -help-build-images for the details.

说实在的,这提示看着很郁闷,让你跳来跳去,就是不能解决问题。

直接创建avd吧,先看下说明:

Usage:
android [global options] create avd [action options]
Global options:
-h –help : Help on a specific command.
-v –verbose : Verbose mode, shows errors, warnings and all messages.
-s –silent : Silent mode, shows errors only.

Action “create avd”:
Creates a new Android Virtual Device.
Options:
-c –sdcard : Path to a shared SD card image, or size of a new sdcard for
the new AVD.
-n –name : Name of the new AVD. [required]
-a –snapshot: Place a snapshots file in the AVD, to enable persistence.
-p –path : Directory where the new AVD will be created.
-f –force : Forces creation (overwrites an existing AVD)
-s –skin : Skin for the new AVD.
-t –target : Target ID of the new AVD. [required]
-b –abi : The ABI to use for the AVD. The default is to auto-select the
ABI if the platform has only one ABI for its system images.

看明白了吧?

android create avd -n test2 -f -p /home/thonatos/test -t 1

然后会有提示:

Auto-selecting single ABI armeabi-v7a
Android 4.0.3 is a basic Android platform.
Do you wish to create a custom hardware profile [no]no
Created AVD ‘test2′ based on Android 4.0.3, ARM (armeabi-v7a) processor,
with the following hardware config:
hw.lcd.density=240
vm.heapSize=48
hw.ramSize=512

创建好了,不过你的模拟器估计一运行就出错吧。(我故意滴。。。别怪我。。)

切换到刚才创建模拟器的目录,然后看看有什么东东,打开config.ini

hw.lcd.density=240
skin.name=WVGA800
skin.path=platforms/android-15/skins/WVGA800
hw.cpu.arch=arm
abi.type=armeabi-v7a
hw.cpu.model=cortex-a8
vm.heapSize=48
hw.ramSize=512
image.sysdir.1=system-images/android-15/armeabi-v7a/

知道该做什么了吧?改吧,把相关的目录改成你自己的,然后再执行一下
emulator @test2

怎么样!是不是已经运行啦?呵呵,恭喜哈!

可能大家都知道,内核源码编译和android源码编译的区别在于,内核是linux的内核

最后把编译后结合起来的命令是

emulator -kernel kernel-qemu -system system.img -data userdata.img -ramdisk ramdisk.img

这个不需要安装avd,上面安装的avd,没有使用自己编译的内核

从现在开始,一个自己编译的android系统就这么运行了

回顾一下:

1、编译android源代码

得到文件:-system system.img -data userdata.img -ramdisk ramdisk.img

2、编译内核

具体怎么编译内核,查看

android内核编译

http://blog.csdn.net/flydream0/article/details/7070392

得到文件:kernel/goldfish/arch/arm/boot/zImage,把它重命名为kernel-qemu,并且把它和源代码编译后的文件放入同一个文件夹下面

3、启动android虚拟机

emulator -kernel kernel-qemu -system system.img -data userdata.img -ramdisk ramdisk.img

更多相关文章

  1. UBUNTU 10.10 编译Android(安卓)2.3.1源码以及SDK
  2. Android(安卓)Studio 编译问题(1)
  3. 编译android平台上的webrtc-chromium
  4. Android.mk添加第三方jar包
  5. Ubuntu安装android源码编译工具
  6. Android编译环境搭建
  7. Android编译问题
  8. Android版本更新及提示安装
  9. Android(安卓)搜索框自动提示及其保存历史记录

随机推荐

  1. ce内存寻址基址
  2. h5图片展示和ajax上传
  3. downloadonly使用小技巧,快速给无外网系统
  4. vSAN集群 无法识别磁盘处理
  5. 关于rabbitmq与kafka的异同
  6. laravel相关备忘
  7. 关于修复用户异常地址的思路
  8. git日常命令
  9. 物联网时代安防行业(包含信息安全行业)所面
  10. 如何用Redis实现分布式锁以及可用性