[Turn] Run the compiled Android in the emulator

Compile SDK

Compile the SDK to get the SDK synchronized with the source code, and generate some tools, in the source code root directory:

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

The compiled SDK is under out/host/linux-x86/SDK. Later, if you use eclipse for development under ubuntu, you can use the SDK you compiled.

The following is to run the image in the simulator. It is recommended to switch to the root user. First, configure several environment variables, set the SDK compiled by yourself as the highest priority, and execute it in the source root directory:

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

This will generate a soft link AndroidSDK pointing to the SDK directory under /etc/ alternatives . This directory mainly stores the information and configuration of some programs that are opened by default by the system. Then /usr/bin/AndroidSDK points to this soft link. Then execute:

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

Add at the end of the file:

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

First of all, you need to set the directory of the emulator tool and so on. I won't go into details.

To add environment variables in .bashrc, as follows

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

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

Here is the location and bin tool directory to set up your output files, no need to explain more, right?

Then enter at the command line:

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

The above is to import the relevant configuration, and then make it take effect.

source ~/.bashrc

Then switch to the output system folder

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

Then create an emulator

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

If you're lucky, it might be up and running now, but I'm clearly not.

Tip one:

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

 

Now that people have prompted, follow the steps and enter the command:

emulator -help-avd

Then the prompt is as follows:

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>’.

Continue following the prompts and enter the command:

emulator -help-virtual-device

Again a reminder:

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.

To be honest, this prompt looks very depressing and makes you jump around, but it just doesn't solve the problem.

Create avd directly, first look at the following instructions:

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.

Do you understand?

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

Then there will be a prompt:

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

Created, but your emulator is estimated to go wrong as soon as it runs. (I dropped it on purpose...don't blame me...)

Switch to the directory where the emulator was just created, and then see what's there, open 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/

Do you know what to do? Change it, change the relevant directory to your own, and then execute
emulator @test2

How! Is it already running? Haha, congratulations!

 

As everyone may know, the difference between kernel source code compilation and android source code compilation is that the kernel is the kernel of linux

The final command to combine after compilation is

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

This does not need to install avd, the avd installed above does not use its own compiled kernel

From now on, a self-compiled android system will run like this

 

To recap:

1. Compile the android source code

Get the file: -system system.img -data userdata.img -ramdisk ramdisk.img

2. Compile the kernel

Specifically how to compile the kernel, see

android kernel compilation

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

Get the file: kernel/goldfish/arch/arm/boot/zImage, rename it to kernel-qemu, and put it in the same folder as the source code compiled file

3. Start the android virtual machine

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326468753&siteId=291194637