Integrating custom Android kernel builds with SDK - android

I'm extending a custom Android kernel fork that originated as a 2.2
Froyo kernel. The build process itself is no problem; just type "make"
and its done. But I'm not sure of what I need to do to make the new
kernel known to other tools in the Android SDK; particularly
the emulator, adb, and the Eclipse debugger.
I've tried various things such as running the emulator with -system and
-userdata arguments on the command line, and these appear to work,
although I hit sporatic problems that leave me unsure. A common problem
I've seen is that sometimes apps "hang", displaying their UI but
refusing to go away even when the home or menu buttons are clicked. I've
tried turning off caching. But the real problem here is that I don't
have a good mental model of how kernel builds should be conveyed to
the SDK.
Should I be copying the build results (.img files) to
~/.android/ perhaps? Or to somewhere in the
SDK folder?
A working recipe would be nice, but better yet would be a
understanding of how the kernel build and SDK tools work together.
For example http://source.android.com/source/using-eclipse.html is
great for recipes but I still don't see how adb and emulator know
where to load .img files from.

When you've built android image the android webpage recommends to run it with emulator command. But you can run the built image in this way because android envsetup command has specified some paths before. For instance, to test my built image I run command:
out/host/linux-x86/bin/emulator -sysdir out/target/product/generic/ -system out/target/product/generic/system.img -ramdisk out/target/product/generic/ramdisk.img -data out/target/product/generic/userdata.img -kernel prebuilt/android-arm/kernel/kernel-qemu -sdcard sdcard.img -skindir sdk/emulator/skins -skin WVGA800 -scale 0.7 -memory 512 -partition-size 1024
So as you can see I specify all the images and all the paths explicitly. This is command to run image in emulator. Out folder is created during the build in your android source root folder.
P.S. Kernel usually refers to Linux kernel of Android. In your case, I think you have changed Android framework.

I've composed a full answer based on the invaluable clues Yury provided. The solution was to add these settings to my .bashrc. The tools (emulator, adb, ddms) in eclipse use these settings to pick up stuff from ANDROID_TARGET_OUT instead of getting them from the prebuilt copies inside the SDK. The CACHE stuff is the standard recommendation.
# Android SDK Build settings
export ANDROID_HOME="/Volumes/DroidImg/android-sdk-macosx"
export ANDROID_SDK_ROOT="$ANDROID_HOME"
export ANDROID_SDK_BASE="$ANDROID_HOME"
export ANDROID_SDK_HOME="$ANDROID_HOME"
export ANDROID_TARGET_OUT="/Volumes/DroidImg/Droid-Kernel/out/target/product/generic"
export USE_CCACHE=1
export CCACHE_DIR="/Volumes/DroidImg/CCACHE_DIR"
ulimit -S -n 1024
Finally, copy the .classpath provided with the SDK as documented on the wiki into the root of the kernel distribution, and "import existing files" into Eclipse. All Java components should now open and build properly in the package explorer. Very handy for exploring but don't forget you have to use ordinary make to build this stuff for real.
/Volumes/DroidImg is a case-preserving disk image I made for MAC-OS work; change this part of the path to suit.

Related

Blank emulator after compililing Android 7.1.1 using Source code, how to get the emulator to work?

I have been trying to get the source code to compile from some time and finally got it compiled. However I am having issues with the emulator where it shows a pop up screen but is quite blank.
I am using Ubuntu Server Xenial and Android 7.1.1 for Nexus6P (but I dont own a Nexus6P so I need to run this on the emulator)
I have tried specifying all the directories such as (-sysdir,-sysdir, -datadir, -kernel, -ramdisk, -system, -data, -cache, -sdcard) although I know that these are supposed to be auto populated by the envsetup.sh file.
The command I used is this:
emulator -kernel ./prebuilts/qemu-kernel/arm64/kernel-qemu -ramdisk ./out/debug/target/product/angler/ramdisk.img -sysdir ./out/debug/target/product/angler/ -cache ./out/debug/target/product/angler/cache.img -system ./out/debug/target/product/angler/system.img -data ./out/debug/target/product/angler/userdata.img -memory 4096 -partition-size 4096 -sdcard sdcard.img -skindir ./sdk/emulator/skins/ -skin WVGA800
I changed the kernel to others such as for ARM/ARM64 but to no avail. All I see is a blank emulator and after changing it to ARM following error:
http://pastebin.com/A04NmNLn
I am at a loss as to why the emulator wont work. Also where is the "image" file with which we can install the Android on Genymotion-type external emulator.
Any help is appreciated!
In order to build AOSP to be run in emulator, there is no need to download any additional binaries. At the same time, emulator cannot run images build for real devices. Therefore, it is required to only download the sources of Android and execute the following commands within the directory with the downloaded sources:
source build/envsetup.sh
lunch aosp_arm-eng #or aosp_x86_64-eng, etc. for details see documentation
make -j4
After the sources are build in the same terminal run the emulator command and the emulator should appear.

What is command to run android AOSP image in plain QEMU?

I want to test TrustZone feature in mainline QEMU and let QEMU run android image. The TrustZone feature is not in qemu-ranchu which is emulator of android built on top of old version qemu. Qemu-ranchu does not include TrustZone feature. So I have to use plain qemu to run trustzone feature on android.
I already compiled the AOSP with arm64 option and I have following image file: ramdisk.img, system.img, cache.img, userdata.img. I want to use qemu-system-aarch64 run these AOSP images.
Could anyone provide some guide line what command should I use to let qemu run these android images? Thanks in advance.
Although I don't know what "TrustZone" is, I think you are confused - "ranchu" is a hardware definition that the new Emulator can use, and it, in turn is based on a much newer Qemu code base.
In any case, you can see exactly what options are being used to run qemu by the Android Emulator (which "wraps" qemu) by starting it from the command line with the -verbose flag, for example:
~/.android-sdk/tools/emulator -avd Nexus_10_API_19 -verbose
I've had some luck running qemu directly by copying those options, and by experimenting with the values that are printed out by the Emulator "wrapper" code.
BTW, you will first need to use Studio's "AVD Manager" to make an avd to use in that command. More information about the command line use of the Emulator can be found here:
Android Emulator Command Line
Good luck!

Run custom ROM on Android Emulator

I downloaded a third-party ROM, and I want to run it on the emulator first before flash it into the phone. Here is the contents of cm-11-20140911-NIGHTLY-p3110.zip:
1. boot.img
2. file_contexts
3. META-INF/
4. recovery/
5. system/
I unpacked boot.img using the script unpack-bootimg.pl and get boot.img-kernel, and boot.img-ramdisk.cpio.gz. Then I repacked the system using the make_ext4fs and got system.img.
I created an AVD and execute:
emulator -system ~/cm11/system_new.img -ramdisk ~/cm11/boot.img-ramdisk.cpio.gz -kernel ~/cm11/boot.img-kernel -avd and442
but all I got is nothing, the emulator screen is just black. There is no log message from adb -s emulator-5554.
Now I am confused:
can the third-party ROM be tested by the emulator?
Am I doing the right way?
Yeah, why not.
We can flash a third-party ROM on Android AVD. But first you must know the following things:
1. The Android Emulator is itself a device, like your Moto G or Xperia
2. Every ROM is device-specific (supports a device-specific Kernel)
(on many sites/blogs you got information like you have to replace system.img file from .android\avd\avdname.avd, but it is technically incorrect, because you also require ramdisk.img.)
To do this, you need to create your own AOSP repository by downloading the particular repository and have to build your own .img files)
You can do it in two ways:
replace files system.img and ramdisk.img from location .android\avd\avdname.avd
Build your own AOSP. Before... make in "lunch" select target as: Emulator (like: genericX86), i.e., generate all emulator specific .img files
I have tried many things. It's a bit critical, but interesting. The following links may help you:
To run your cooked ROM on Emulator (link down. Try this, from archive.org).
To Create AOSP Project

which files does an emulator need to run at least?

I have aready build a emulator with new kernel from source.
And with the built file and source,the project folder is so huge.So,i want to part them off.
Here,i download the sdk tools.
So,i wonder which files does a emulator need at least?such like,system.img and what?
(What's more,i have also build a new kernel,and i want to run the emulator with this new kernel)
thx,in advance!
attached:
After a long time searching,i put the minimal files in a folder like:
:~/droidls
hardware-qemu.img system.img userdata-qemu.img
ramdisk.img userdata.img zImage
And then,i cd to this folder and put the android-sdk-linx/tools path into host os's PATH variable.
At last,I try to use the following command to start the emulator:
emulator -kernel zImage -ramdisk ramdisk.img -sysdir ~/droid -datadir ~/droid -data userdata-qemu.img -system system.img -initdata userdata.img
But it fails.
And with the built file and source,the project folder is so huge.
Please Describle it How the project folder got huge after built it.
So,i wonder which files does a emulator need at least?such
like,system.img and what?
Yes, its nice question. as Per the Official Documentation,
To use the emulator, you first must create one or more AVD
configurations. In each configuration, you specify an Android platform
to run in the emulator and the set of hardware options and emulator
skin you want to use. Then, when you launch the emulator, you specify
the AVD configuration that you want to load.
Each AVD functions as an independent device, with its own private
storage for user data, SD card, and so on. When you launch the
emulator with an AVD configuration, it automatically loads the user
data and SD card data from the AVD directory. By default, the emulator
stores the user data, SD card data, and cache in the AVD directory.
you can Go through the Here For More Description
What's more,i have also build a new kernel,and i want to run the
emulator with this new kernel
For query regarding Running with your New Kernal and running it with your emulator you can Go through Android Kernal Compile and Test with Android Emulator
Hope it Will Help
For running an application on device or emulator Android Package .apk file is needed. A .apk files contains .dex file(files converted to Dalvik byte code), resources files .arsc, Uncompiled resource and AndroidManifest.xml. For more detail see the developer guide document Building and Running.

Building Android from source - emulator and AVDs [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have built the Android source for the emulator. I read in the Android Source documentation that the path to 'emulator' is added autmatically during a successful build. However I have two questions about this:
If I open a new shell or close my existing shell, 'emulator' is no longer found. Surely I don't have to build each time I want to run the emulator?
If the emulator requires an AVD how do I create and manage these given there is no Android SDK on my machine?
Thanks,
Jack
SOLUTION to part 2.
I needed to create an environment variable called ANDROID_PRODUCT_OUT. From the the following command:
emulator -help-build-images
I read...
The emulator detects that you are working from the Android build
system by looking at the ANDROID_PRODUCT_OUT variable in your
environment.
If it is defined, it should point to the product-specific directory
that contains the generated system images.
I then did a search for 'system.ing' in my 'out' directory. since I am building for the emulator the image was in:
out/target/product/generic
I added the following line to my .bashrc file:
export ANDROID_PRODUCT_OUT=/home/jack.wootton/code/out/target/product/generic
I was then able to run the emulator from:
/home/jack.wootton/code/out/host/linux-x86/bin
SOLUTION to part 1.
I don't know about Android Virtual Devices, so this question still stands - however I did not need to provide one to run the emulator after doing a successful build and setting the ANDROID_PRODUCT_OUT environment variable.
Update to solutions
Apparently variables such as ANDROID_PRODUCT_OUT should be automatically created during a build and using the envSetup.sh script. I guess something has gone wrong with my environment setup for this not to happen.
You shared that:
Apparently variables such as ANDROID_PRODUCT_OUT should be automatically created during a build and using the envSetup.sh script. I guess something has gone wrong with my environment setup for this not to happen.
I ALSO ATTEMPTED to get this to work and LEARNED that:
lunch full-eng sets up all the appropriate env
to check it, simply run:
env | grep ANDROID
and you will see all the appropriate env variables setup.
These are local to the current shell only!
emulator then does what it should.
When I came back to the shell later, I simply ran lunch full-eng again to restore my environment.
I hope this helps others as well!
Just do the following:
source build/envsetup.sh or . build/envsetup.sh
setpaths
That does the trick. Make sure you run it from your source directory.
To check my built sources for emulator I've created the following script in the root folder of the project. I run it from another command line and it does not require to run all the time running . build/envsetup.sh and lunch full-eng commands. You can edit this script for your needs and if you need to run other device - simply change folder.
out/host/linux-x86/bin/emulator -sysdir out/target/product/generic/ -system out/target/product/generic/system.img -ramdisk out/target/product/generic/ramdisk.img -data out/target/product/generic/userdata.img -kernel prebuilt/android-arm/kernel/kernel-qemu -sdcard sdcard.img -skindir sdk/emulator/skins -skin WVGA800 -scale 0.7 -memory 512 -partition-size 1024
You can add these to your .bashrc file
export ANDROID_PRODUCT_OUT=$ANDROID_SRC/out/target/product/generic
export ANDROID_BIN=$ANDROID_SRC/out/host/linux-x86/bin
PATH=$ANDROID_BIN:$PATH
In fact, the program "emulator" is just a wrapper for the real emulator-qemu, such as emulator-arm or emulator-x86. The "emulator" you invoked will collect the arguments you typed in and find the proper emulator-qemu to execute.
The problem you met is that you did not explicitly describe which image/avd you want to start. You can either using the argument "#avd YOUR-AVD_NAME" or "ANDROID_PRODUCT_OUT" environment variable to set the dir where your avd is placed. BTW, avd dir contains some files to describe how this device looks like.
". build/envsetup.sh" is the script that set the environment variables for the Android build process. So it is easy to understand why "ANDROID_PRODUCT_OUT" will be set at that time. Its default value should be "PATH/TO/ANDROID/out/target/product/generic".
PS: If you want to know more, you can refer to the source file: "PATH/TO/ANDROID/external/qemu/android/main-emulator.c". You can find the emulator main there.

Categories

Resources