【转】模拟器中运行编译好的Android -程序员宅基地

技术标签: 运维  移动开发  嵌入式  

编译SDK

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

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

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

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

[plain] view plain copy
  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 plain copy
  1. $ gedit ~/.bashrc  

在文件末尾添加:

[plain] view plain copy
  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

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/gdfdfg/article/details/84650373

智能推荐

SSL编程指南_sslv23-程序员宅基地

文章浏览阅读1.3w次,点赞16次,收藏83次。本文将介绍如何使用openssl APIs 实现一个简单的SSL 客户端和服务端虽然SSL客户端和服务端在创建和配置上有所区别,但它们本质上的步骤可以总结为如下图,具体步骤将在后面章节介绍:初始化SSL库在SSL应用程序中调用其他Openssl APIs,需要先用下面的APIs进行初始化:SSL_library_init(); /* 为SSL加载加密和哈希算法 */_sslv23

Java笔记5.0-程序员宅基地

文章浏览阅读75次。if条件结构基本if条件结构if(条件){}注意:当if关键词后的一对大括号里只有一个语句时,可以省略大括号。2.多重复if条件结构if(条件1){}else if(条件2){}else{}应用于只有一个if条件不能解决的问题,可以将问题的条件更详细地表示。3.嵌套if条件结构嵌套if选择结构就是在if里嵌入if选择结构,如下if(条件){if(条件){代码...

Paul Graham:未来的互联网创业(上)-程序员宅基地

文章浏览阅读63次。根据Paul Graham的简历,他是一个计算机博士,一个程序员,一个风险投资家。 ...

C#入门5.7——迭代语句之foreach语句_c# 中迭代变量 与集合变量-程序员宅基地

文章浏览阅读372次。foreach提供了一个for语句的捷径,而且还促进了集合类更为一致。格式foreach(类型 变量 in 集合) //注意集合二字。{代码体}补充:string类型可以看成是char类型的一个集合新语句char.IsWhiteSpace(c) //判断c是否为空格例子:将语句识别为单词并逐行输出using System;using Syst_c# 中迭代变量 与集合变量

django 中路由的使用 path 和 re_path的区别 url_django re_path 使用方法-程序员宅基地

文章浏览阅读719次。django 中路由的使用_django re_path 使用方法

uni-app中uni-table的uni-tr无点击事件_uniapp uni-table 点击事件-程序员宅基地

文章浏览阅读1.4k次,点赞3次,收藏8次。增加点击行点击事件(很多事件都没有),这个问题很久就有人在其官方论坛提出,但官方一直没有解决。有时开发就是那么“山重水复疑无路”,等方法二觉得是自己最后的无奈的选择时。笔者在写这篇文章时,为了信息的准确和完整,再去。标签里面,绑定相同的事件(如果想实现点击单元格触发不同的事件就可以定义不同的方法)。,但这样样式会改变,如下图所示。(后来在uni-app的论坛的回答也看到类似的。相比于方法一,优点是表格的样式不变,缺点是代码凌乱复杂。总之,最优的解决方法应该是方法三,期望有人去改善。本文记录用于记录使用。_uniapp uni-table 点击事件

随便推点

vue项目中的登录功能实现_trottle(_wxmnplogin, 1000)-程序员宅基地

文章浏览阅读1.6k次,点赞2次,收藏14次。今天找了个开源的vue项目,要在此基础上改动,刚看到登录功能,封装的挺好,记录下,顺便捋捋思路,方便以后使用1、界面部分,就正常的登录界面,把重点的代码贴上(红色箭头是登录事件)2、js部分:输入用户名和密码,点击登录按钮后,触发this.throttleLogin方法,在此设置了一个节流函数throttle,此函数参数主要为调用的函数方法以及规定时间内仅触发一次。节流函数3、调用了this.login方法,在此方法中,将api请求封装到单独的模块中,该vue页面引用..._trottle(_wxmnplogin, 1000)

Visio首要事项闪退-程序员宅基地

文章浏览阅读2.5w次,点赞36次,收藏25次。网上有很多首要事项三个选项无论怎么选都直接闪退的情况,我自己遇到后瞎捣鼓解决了,把方法发出来给后来者借鉴。1、在设置-应用中找到Visio,应该叫“Microsoft Visio Professional 2013”。2、单击右边三个小点,选择“修改”。3、选“输入产品密钥”。4、复制这个失效密钥 27W4Q-T9N3J-JWX46-M7K96-GMQ73 并输入。5、因为已经安装过了就不需要自定义,所以选择继续、继续就行。6、提示重启系统,直接叉掉,没有修改安装文件没必要重启。.._首要事项

Java 设计模式 - Builder_java builder设计模式-程序员宅基地

文章浏览阅读137次。Java Design Partterns - Builder_java builder设计模式

[源码和文档分享]基于C++实现的LZW压缩算法-程序员宅基地

文章浏览阅读53次。1 特点 基于C++实现的LZW压缩算法,特点如下所示: 使用stl::map键值对作为字典存储 感觉算是简单的文件操作 字典无限长,字典自生长。但是字典只能解析存储ascii编码之类存在,中文符号之类的碰到就挂 2 逻辑设计 2.1 总体思路 ..._c++基于字典的无压缩算法lzw和lz77

自己动手编程实现“电子地图下载器_地图下载器实现原理-程序员宅基地

文章浏览阅读2.1k次,点赞3次,收藏3次。自己动手编程实现“电子地图下载器”请联系本文作者(QQ:442134556)获取源码电子地图对于国土规划、交通运输、水利设计、农林地质等部门的测绘、测量专业设计人员至关重要。国内已有一些公司提供下载软件,如迈高图(megomap)地图下载器、水经注(rivermap)万能地图下载器、BIGEMAP地图下载器、全能电子地图下载器等。这些软件的使用费从几百元到几千元不等。其实,绝大部分地理信息图..._地图下载器实现原理

HN8145X6/HS8145X6安装虚拟机OpenWRT-程序员宅基地

文章浏览阅读927次。(5)21.02.2版本和电信插件管理平台不兼容,电信平台起不来,所有的库都在原来的地方,但是ldd appmgr会报告一堆relocation。(1)125版以上固件的tar是残废的,不能正确解析跨目录的软链接,需要自行另外找版本;(2)默认network服务是关闭的,不要随意乱配和启动,可能会挂掉,特别是CPU口eth0,挂了用上面的软链接方法恢复,要拼手速。(3)默认防火墙firewall服务也是关闭的,,不要随意乱配和启动,可能网络会挂掉连不上,挂了用上面的软链接方法恢复,要拼手速。_hn8145x6