I know this is a recurrent question when working with the Android emulator, but is there a way to force the emulator to accept persistent changes to /system
?
The emulator is based on QEMU, so it should be possible, in theory, to force the system
image to behave the same way userdata
(for instance) does, but I'm not familiar with how QEMU handles things. Any pointers?
On Android Studio 4.0 and above you can select Device File Explorer then select sdcard folder. Select a folder you want to save your files to, then right click and select upload. To download content from emulator select the folder or file and click save as option.
The android tools create an . android folder in your users home folder. This folder contains an avd folder in which a separate folder for each virtual device exists. In each of this folders a file called sdcard.
In Android Studio go to “Tools (Menu Bar) >Android > AVD Manager. Click on the “Create Virtual Device” button. Select “Phone” or “Tablet” as Category and select the device which you want to use to make a Virtual Device. Then click on the “Next” button.
At the moment (with Build Tools v26, if Google doesn't change things as often as they do) if you use the -writable-system
directive while booting up the emulator from the command line, it will allow persistence to the /system
partition through reboots. That is you will be able to write to the /system
partition and if you reboot, the changes will still be maintained.
emulator -avd <AVD_NAME> -writable-system
This will also persist your changes to a qcow2
image file usually in .android/avd/<AVD_NAME>.avd/system.img.qcow2
You can even copy this system.img.qcow2
file, wipe the data off the AVD using the -wipe-data
directive, place this file back into the directory, reboot and the system changes you made initially will still be persisted. (Caveat: at least for now, coz Google keeps changing things)
Update: The -nand
option was apparently removed from the most recent versions of QEMU, so the following may not work anymore.
Update: See the accepted answer for the current way of doing things.
Yury's answer is the common one, but if you want to be able to script things (which is what I want in the end), you need to be able to find the emulator image in the /tmp
directory.
I discovered that you can override QEMU's behavior. This is a bit hackish, but it works, so I ended up doing this :
system.img
from the platform directory to your AVD directory.0x1f400000
.Run the emulator in read-write mode :
emulator -avd Galaxy_Nexus -qemu -nand system,size=0x1f400000,file=/home/fx/.android/avd/Galaxy_Nexus/system.img
(If you put the emulator in verbose mode, you'll notice that it will, by default, use initfile=
instead of just file=
)
Make your changes, they are immediately saved to the local system.img
emulator -avd Galaxy_Nexus
, and it'll use your changesUpdate: If scripting, QEMU does not sync changes immediately to the image, so if you're rebooting immediately after changing something, chances are you will lose data. I'm looking for a way around this...
Next update: Use adb -e emu kill
to stop the emulator. reboot
will just do bad things.
It's actually a very good question. I had the same troubles. Here are my findings. Actually, I use Ubuntu and I'll describe the steps for Ubuntu. If you use Windows, you should just change the paths.
example.avd
android-sdk-linux/platforms/android-10/images
to ~/.android/avd/example.avd
emulator -avd example
mount -o rw,remount -t
yaffs2 /dev/block/mtd0 /system
(to discover the partition use
command cat /proc/mtd
)/tmp/android-<your_computer_name>
with strange name like:
emulator-PQ7LgE
and copy it in ~/.android/avd/example.avd
system.img
and rename copied tmp emulator into system.img
cache.img
, userdata.img
and userdata-qemu.img
from
~/.android/avd/example.avd
Good luck!
The solution #2 is amazing.
Here are some hints if you are using MS Win as host AVD directories are located as below, but the "short" path names should be used as file= path parameter. The quoted path variant doesn't work for some reason.
Win XP: C:\Documents and Settings\ (username) \ .android\avd\ ... Short C:\DOCUME~1\ (username) \ANDROI~1\avd\ ...
Win 7 C:\Users\ (username) \ .android\avd\ ...
You can create an own bat file, say "startrw.bat" as per following example:
@echo off
C:\<ADTFOLDER>\sdk\tools\emulator -avd <AVDNAME> -qemu -nand system,size=0x1f400000,file=C:\DOCUME~1\<USERNAME>\ANDROI~1\avd\<AVDNAME>.AVD\system.img
cd C:\<ADTFOLDER>\sdk\platform-tools
echo .
echo Wait ...
echo .
echo When emulator is FULLY loaded press any key to connect adb shell to it
echo To make /system writeable type in adb shell:
echo .
echo -----------------------------
echo mount -o rw,remount /system
echo -----------------------------
echo .
echo You can use the Eclipse ADT DDMS File Browser to browse or push-pull files now.
echo .
echo Closing this window closes the emulator !
echo .
echo Wait emulator to load Android. When done
pause
C:\<ADTFOLDER>\sdk\platform-tools\adb shell
This way you can load in one click. Once finished modifying, just close the current command window to kill the emulator.
It takes long time for most of things to load like Emulator, the ADT editor, Hooking DDMS file browser (you need to click on the emulator line left side to see the files tree on right window) and so on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With