Search This Blog

20 March 2012

Modify the emulator system.img

As a followup to my earlier post, I thought I would show how to modify the system.img the emulator is using.

This assumes that you are building Android and want to use some of the generated APKs inside the stock emulator.  That isn't the only scenario, but it's the one I am covering here.

First, we need to determine where the images are being loaded from. In this case my AVD is called "ics".
malachi@onyx:~/work/redo_system$ grep sysdir ~/.android/avd/ics.avd/config.ini
image.sysdir.2=system-images/android-14/armeabi-v7a/
image.sysdir.1=add-ons/addon-google_apis-google_inc_-14/images/armeabi-v7a/

Let's grab a local copy of those files
malachi@onyx:~/work/redo_system$ cp $ANDROID_HOME/add-ons/addon-google_apis-google_inc_-14/images/armeabi-v7a/* .

This time around, we are interested in the system.img. Let's unpack it.
malachi@onyx:~/work/redo_system$ mkdir unpacked
malachi@onyx:~/work/redo_system$ cd unpacked/
malachi@onyx:~/work/redo_system/unpacked$ unyaffs ../system.img
end of image

Replace a couple apps
malachi@onyx:~/work/redo_system/unpacked$ cd app
malachi@onyx:~/work/redo_system/unpacked/app$ cp ~/work/ics/out/target/product/SomeProduct/system/app/Contacts.apk .
malachi@onyx:~/work/redo_system/unpacked/app$ cp ~/work/ics/out/target/product/SomeProduct/system/app/ContactsProvider.apk .

Repack the system.img
malachi@onyx:~/work/redo_system/unpacked/app$ cd ../..
malachi@onyx:~/work/redo_system$ rm system.img
malachi@onyx:~/work/redo_system$ ~/work/ics/out/host/linux-x86/bin/mkyaffs2image unpacked system.img

Point our AVD to our new images
malachi@onyx:~/work/redo_system$ nano ~/.android/avd/ics.avd/config.ini
image.sysdir.2=system-images/android-14/armeabi-v7a/
image.sysdir.1=/home/malachi/work/redo_system/

The old userdata may not be compatible with your new apps. Make sure to use -wipe-data:

malachi@onyx:~/work/redo_system$ emulator -avd ics -show-kernel -scale 0.70 -memory 1024 -logcat 'dalvikvm:S,StrictMode:S,*:D' -partition-size 1024 -wipe-data

You are now running a slightly modified emulator...

No comments:

Post a Comment