`

【转】模拟器中运行编译好的Android

 
阅读更多

编译SDK

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

[plain] view plaincopy
  1. $ sudo make PRODUCT-sdk-sdk  

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

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

[plain] view plaincopy
  1. $ update-alternatives --install /usr/bin/AndroidSDK AndroidSDK ./out/host/linux-x86/sdk/android-sdk_eng.root_linux-x86 255  

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

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

在文件末尾添加:

[plain] view plaincopy
  1. export ANDROID_SDK_HOME=/usr/bin/AndroidSDK  
  2. export PATH=$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

分享到:
评论

相关推荐

    SDL Android 例子源码可用工程,实测编译通过在模拟器运行(SDL 2.0 for Android)Eclipse

    SDL Android 例子源码可用工程,实测编译通过在模拟器运行(SDL 2.0 for Android),工程目录名叫AndroidTst2,编译通过可用, sdl source code for android android source code for sdl 2.0 这个工程的文件夹...

    编译并运行Android4.0模拟器.pdf

    编译并运行Android4.0模拟器.pdf

    fba安卓模拟器源码编译APP demo完美运行

    fba安卓模拟器源码编译APP demo完美运行,下载后按帮助操作即可。性能比强悍,适合比较低端的设备运行。另外兼容的游戏rom也比较多,基本可以淘汰mame实现性能之王。无积分下载可以点头像找我发给你。

    使用命令行+Ant编译和运行Android模拟器

    在使用命令行+Ant学习Android的过程中,自己累积的一些常用在命令下的编译和运行Android的命令,希望能带给你一些帮忙。

    Nesoid_API27_andoridfc模拟器_android_

    android上可以编译运行的FC模拟器

    模拟器专用android kernel2.6 (支持netfilter,ko文件加载与卸载)

    1.如何让android模拟器运行时使用自己编译的内核? 首先进入eclipse,点avd manager,新建个模拟器(android1.5~android2.3.3都行) 假设新建模拟器名叫avd22 然后用下列命令(在命令行下输入): $ANDROID_SDK/tools/...

    android内核编译手册(图文并茂)

    手把手教你在linux下编译android内核并在模拟器中运行

    图解Google Android内核编译教程

    当然这不是这篇文章的重点,我们现在的目的是要编译出一个可以在模拟器上运行的系统内核. 和标准的Linux开发流程一样,Android平台开发的一个很重要的基础工作就是对其内核的编译和移植。本文结合Android的开发文档...

    让Qt应用程序跑在Android上

    Qt最大的优势就是跨平台,一次性开发的Qt应用程序,可以跑Windows、跑linux、跑MAC……如今移动平台android操作系统如此火爆,Qt当然不能放过对android的支持,对了,还有iphone/ipad。而且,c++开发者们,想做...

    [中文]Basic4android新手指南_第3章第二个程序(SecondProgram.b4a)

    Basic4android将代码编译成Android原生(native)应用,无需其它运行环境的支持。与其它的集成开发环境不同,Basic4android是完全用于Android应用开发的开发工具,不支持其它平台。Basic4android包含一个强大的GUI...

    [中文]Basic4android新手指南_第1章从这里开始

    Basic4android将代码编译成Android原生(native)应用,无需其它运行环境的支持。与其它的集成开发环境不同,Basic4android是完全用于Android应用开发的开发工具,不支持其它平台。Basic4android包含一个强大的GUI...

    自写AndroidStudio JNI编程静态注册 编译调用so源码

    自写AndroidStudio JNI编程静态注册 编译调用so,雷电模拟器3可正常运行。Android Studio直接导入项目即可使用

    制作独立的Android模拟器实现方法

    通常,我们开发Android应用程序的时候,都是使用模拟器来运行程序,要么是SDK环境下,要么是在源代码BUILD环境下使用。在SDK环境下,结合Eclipse和ADT,使用模拟器很方便,而BUILD环境下,也是很简单地使用emulator...

    [中文]Basic4android新手指南_第5章屏幕大小与分辨率

    Basic4android将代码编译成Android原生(native)应用,无需其它运行环境的支持。与其它的集成开发环境不同,Basic4android是完全用于Android应用开发的开发工具,不支持其它平台。Basic4android包含一个强大的GUI...

    python3-android:适用于Android的Python 3交叉编译工具

    (可选) make test以设置Android模拟器并运行自动Python回归测试。要求建筑要求: 可以编译Python(适用于hostpython)的有效主机工具链。 耐心。 测试要求: Java 6使用Android SDK管理器。 awk和tr用于一些设置...

    jetboy android游戏 源码

    eclipse 编译 模拟器运行通过。 android SDK1.6 eclipse 飞机游戏 源码

    反编译工具

    Android Killer 是一款可视化的安卓应用逆向工具,集Apk反编译、Apk打包、Apk签名,编码互转,ADB通信(应用安装-卸载-运行-设备文件管理)等特色功能于一 身,支持logcat日志输出,语法高亮,基于关键字(支持单行...

    [中文]Basic4android新手指南_第10章变量与对象

    Basic4android将代码编译成Android原生(native)应用,无需其它运行环境的支持。与其它的集成开发环境不同,Basic4android是完全用于Android应用开发的开发工具,不支持其它平台。Basic4android包含一个强大的GUI...

    夜神安卓模拟器 ,电脑玩手游的新一代神器

    夜神安卓模拟器 ,电脑玩手游的新一代神器,夜神安卓模拟器是一款采用类手机界面视觉设计的PC端桌面软件,采用内核技术(基于Android7.0版本内核针在电脑上运行深度开发),具有同类模拟器中领先运行速度和稳定的...

    Android代码-dumpDex

    下载源码编译或者下载apk包并安装,应用xposed模块后重启,运行加固的应用后,插件会自动将dex文件dump到 /data/data/包名/dump 目录 apk文件不会实时更新,获取最新apk请自行编译源码 源码编译 将源码下载或者clone...

Global site tag (gtag.js) - Google Analytics