I haven't been able to find anything on this. Apologies if this duplicates anything in existence.
I'm currently have a virtual version of Ubuntu 10.10 accessing a shared folder in my main OS (Arch Linux) to build Android. I can successfully build it and run the emulator from my virtual machine. (The make file updates my shell appropriately, correct?) When I go to my actual OS and try to run the same emulator, I get an error that states:
$ ./out/host/linux-x86/bin/emulator
emulator: ERROR: You did not specify a virtual device name, and the system directory could not be found
I have tried setting ANDROID_PRODUCT_OUT to the same value on my actual computer, but I still get the same error. Is this just a simple error, or should I just stick to running the emulator on my virtual machine?
This isn't a complete answer, but I was able to do what I wanted to by creating an Ubuntu partition on my computer and chrooting into it and forwarding the X display.
References for doing this:
http://source.android.com/source/initializing.html
https://wiki.archlinux.org/index.php/Change_Root
After setting up my Ubuntu environment, I made the following script to chroot into it (this is nearly taken directly from the 2nd source):
xhost +
cd /mnt/ubuntu
mount /dev/sda2 /mnt/ubuntu
mount -t proc proc proc/
mount -t sysfs sys sys/
mount -o bind /dev dev/
mount -t devpts pts dev/pts/
mount -o bind /mnt/data mnt/data/
mount -o bind /home home/
chroot /mnt/ubuntu /bin/sh -c "export DISPLAY=:0.0; /bin/bash -i"
umount {proc,sys,dev/pts,dev}
umount {mnt/data,home}
cd .. && umount ubuntu
Then go to your android root directory ($android), set up the environment and build it. Starting the emulator should then start it in the current X session.
cd $android
. build/envsetup.sh
lunch full-eng
make -j16
emulator
Related
I am running Android emulator (emulator version 30.5.5.0) and the avd: Pixel_3a_API_30_x86 from AndroidStudio.
Using adb.exe (Android Debug Bridge) I try to copy a file from the Windows host to the emulated Android /system/... folder, but I haven't been able to after trying different things like this tutorial:
I run the android emulator from the command line to specify the parameter -writable-system:
cd C:\Users\%username%\AppData\Local\Android\Sdk\emulator
emulator -avd Pixel_3a_API_30_x86 -writable-system
Then from another command-line window while the emulator is running:
cd C:\Users\%username%\AppData\Local\Android\Sdk\platform-tools
adb root
adb shell "mount -o rw,remount /"
'/dev/block/dm-0' is read-only
adb push MyFile.txt /system/etc/security/cacerts
Then I get the error:
ERROR:
MyFile.txt: 1 file pushed, 0 skipped. 0.1 MB/s (950 bytes in 0.011s)
adb: error: failed to copy 'MyFile.txt' to '/system/etc/security/cacerts/MyFile.txt': remote couldn't create file: Read-only file system
How can I copy the file from Windows to Android /system ?
The tutorial in the link was missing some commands and the web page was not updated with the latest version from GitHub.
Here is the final sequence (for API LEVEL > 28):
adb root
adb shell avbctl disable-verification
adb reboot
adb root
adb remount
adb push MyFile.txt /system/etc/security/cacerts
Run adb root && adb remount first.
I would like to use:
http://newandroidbook.com/tools/jtrace.html
To do it, I started avd emulator based on x86-64 CPU. Now, I do:
adb push jtrace.x86 /data/local/tmp
adb shell
cd /data/local/tmp
./jtrace.x86
And, as a result, I've got an error:
/system/bin/sh: ./jtrace.x86: No such file or directory
However, the file exists in fact.
How to solve it?
Anyone know how to edit /etc/hosts file inside an android studio emulator running in nougat? I will be editing it so I can use my virtual host in my local web server. I tried editing it through terminal using adb however, it is returning Read-only file system. Tried also using chmod but still it fails.
Update:
I also tried pulling and pushing files using adb
$ ./adb -s emulator-5554 push ~/Desktop/hosts /system/etc/hosts
adb: error: failed to copy '/Users/Christian/Desktop/hosts' to '/system/etc/hosts': couldn't create file: Read-only file system
1) android-sdk-macosx/tools/emulator -avd <avdname> -writable-system
2) ./adb root
3) ./adb remount
4) ./adb push <local>/hosts /etc/hosts
Android file host can be
/etc/hosts <--- This worked for me
/etc/system/hosts
/system/etc/hosts
Check
1) ./adb shell
2) cat /etc/hosts
3) ping customsite.com
Step by Step
Don’t Create the AVD with a Google Play image.
Use for example Google APIs Intel x86 Atom System Image.
Start the emulator with the following command…
emulator.exe –avd <avd name> -writable-system
For example:
C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\emulator>emulator.exe -avd Pixel_API_25 -writable-system
emulator: WARNING: System image is writable
HAX is working and emulator runs in fast virt mode.
audio: Failed to create voice `goldfish_audio_in'
qemu-system-i386.exe: warning: opening audio input failed
audio: Failed to create voice `adc'
Root and Remount the AVD like the followings…
C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\platform-tools>adb root
C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\platform-tools>adb remount
remount succeeded
C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\platform-tools>adb shell
eneric_x86:/ # cd system
generic_x86:/system # cd etc
generic_x86:/system/etc # cat hosts
127.0.0.1 localhost
::1 ip6-localhost
generic_x86:/system/etc # echo "192.168.1.120 ilyasmamun.blogspot.com" >> hosts
generic_x86:/system/etc # cat hosts
127.0.0.1 localhost
::1 ip6-localhost
192.168.1.120 ilyasmamun.blogspot.com
generic_x86:/system/etc #
Here is how i was able to do it working on OSX. After reading a bunch of different instruction nothing seemd to work for me untill someone mentioned that you have a very narrow window for copying the file from your disk to the emulated device or it becomes read-only again
Start your emulator.
In your terminal find the folder "platform-tools" for your devices
Prepare the hosts file you want to copy to your device (in my case i put it on desktop)
String together a bunch of commands to copy the file quickly. This is what worked for me ./adb root && ./adb -s emulator-5554 remount && ./adb -s emulator-5554 push ~/Desktop/hosts /system/etc/hosts 'emulator-5554' is the name of my device which you can find by typing ./adb devices
after that the terminal responded with
restarting adbd as root
remount succeeded
[100%] /system/etc/hosts
you can veryfy the copy was successfull by ./adb shell and then cat /system/etc/hosts
I was then able to connect to my virtual hosts from the emulated device
Just to be complete here is how my hosts file looked like
10.0.2.2 my-virtual-host
I hope this helps someone as i spet quite some time trying to figure this out.
Below are the steps I followed on my Windows machine on Windows Terminal:
Run the following command to know your AVDs:
emulator -list-avds
Run the following command to open the emulator for writable mode:
emulator -avd Pixel_XL_API_29 -writable-system -no-snapshot-load
Replace Pixel_XL_API_29 with your AVD name.
Ignore the warnings there.
In a new Terminal tab run the following commands:
adb root
adb shell avbctl disable-verification
adb reboot
Wait for your emulator to reboot. It can take upto 1 minute.
When the emulator is rebooted, run the following commands:
adb root
adb remount
You will get a remount succeeded message after that:
Now is the time to push our host file from Windows machine to Android's emulator
adb push D:\hosts /system/etc/
D:\hosts is the location of the hosts file present at the D drive of my Windows machine.
/system/etc/ is the location in Android's emulator where we want to copy that file.
After successfull operation you will see a message like this:
To verify that the hosts file has been pushed you can run the following commands:
adb shell
cd system
cd etc
cat hosts
You will see the contents of hosts file in the Terminal:
I was able to edit the /etc/hosts file by launching the emulator with -writable-system and remounting the emulator using adb remount. After that the hosts file inside the emulator is editable. I tried pushing/replacing the file and succeeded.
Another approach to this matter would be to use the adb command line tool.
Make sure you have in path emulator and tools
export ANDROID_HOME="/Users/YOUR_USERNAME/Library/Android/sdk"
export PATH=$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$PATH
EDIT: For Windows should something like this (instead of tools required platform-tools [or the path where adb resides])
C:\Users\YOUR_USERNAME\AppData\Local\Android\sdk\platform-tools
C:\Users\YOUR_USERNAME\AppData\Local\Android\sdk\emulator
Check device name (ideally it would be to have a short name without spaces, eg. API30X86)
emulator -list-avds
Then launch the emulator with the following arguments:
emulator -avd YOUR_AVD_NAME -writable-system -no-snapshot-load -no-cache
Run the following commands to run as root and remount the partition system as root
adb devices #you should see your devices
adb root
adb shell avbctl disable-verification
adb reboot
adb root
adb remount
After remount, you should be able to push the edited host file from your machine to the emulator.
adb push ~/Documents/hostsandroid /etc/hosts
Now you should be able to see your hosts file with Device File Explorer from Android Studio.
EDIT: In the case, you don’t see the Device File Explorer, you can check the Event Log if Android framework is detected. If so, click Configure and you're done.
When you are going to run again and push new changes with a new session, you’ll only have to do:
adb root
adb remount
adb push ~/Documents/hostsandroid /etc/hosts
Follow the below 3 steps :
Start emulator in writable mode : ./emulator -avd <emulator_name> -writable-system
remount : adb remount
push the hosts file attached : adb push hosts /system/etc/
Note :
Run one and only one emulator_name with above steps
executable emulator is located within android-sdk. For me it was under sdk/emulator.
Attached hosts file will resolve www.facebook.com to 127.0.0.1, hence blocks www.facebook.com on emulator.
First find your system hosts file and copy it to desktop
Then create a virtual device Nexus 5 with system image Nougat x86_64 Android 7.1.1 (non Google API version) once it is created
Then goto /Android/sdk/emulator in terminal then run the below code please add your own device name below as mine was Nexus_S_API_25 =>
./emulator -writable-system -netdelay none -netspeed full -avd Nexus_S_API_25
After that Open a new terminal and goto this location
/Android/sdk/platform-tools
then run
./adb root
./adb remount
./adb push ~/Desktop/hosts /system/etc/hosts - (It will copy your Desktop/hosts file and paste it into your emulator hosts file which is /system/etc/hosts)
That's it your emulator hosts file is updated Now if you want to re-check then run the below code
./adb shell
cat /system/etc/hosts (it will show you the emulator hosts file)
Restart the emulator to see the changes
./adb reboot
Tedious, but effective, you can build a new hosts file, line by line within your emulator shell.
Remount Emulator
You can edit/remount your emulator (to get a writeable filesystem) in your PC/Mac/linux command line / powershell / terminal.
(Stop your emulator if it's already running, then...):
emulator -avd <avdname> -writable-system
(this starts up a new emulator with a writable file system)
Still within your PC/Mac/Linux terminal run these two commands:
adb root
adb remount
Then connect to your running emulator via a shell:
adb shell
This part below is run from inside your emulator, inside the shell connection you just made.
Give yourself root access:
su
Change directory to where the hosts file is kept:
cd /etc
To make your emulator defer to your development machine's hosts file or DNS for a given domain, add a domain entry using ip of 10.0.2.2.
Example of appending a new domain entry line to emulator hosts file:
echo '10.0.2.2 mydev.domain.com' >> hosts
This 10.0.2.2 is a special address for Android emulators. It will proxy DNS requests for that domain to your development machine. So whatever IP address your PC/Mac/Linux machine hosts file lists for mydev.domain.com, the Android emulator will use it.
You can now exit the root shell & your emulator shell:
exit
exit
(1st gets you out of su. 2nd exits from the emulator shell, dropping you back into your development machine's terminal).
You're done. You can open up a web browser inside your emulator, type the domain you just added to hosts into the address bar and check the emulator is routing that domain properly.
Remount failed
If you're on Android emulator 29+ and getting
remount failed
when calling adb remount, check out the workaround by Kidd Tang here.
You can use the ADB Shell to edit the file by changing the access (Read Only to RW)
Try #P.O.W answer,
Make sure you have a blank line after the last entry of the hosts file
If you use tabs in the hosts file, replace them with spaces
Restart Android and try again:
adb reboot
place all these export in z shell using terminal
vim ~/.zshrc press enter
then zshell will open
then press i
past all the export (verify the path i have used all default location for instalation)
then press esc
then press this :wq!
press enter
close terminal and open it again
export PATH="$PATH:$HOME/Dev/flutter/bin"
export GEM_HOME=$HOME/.gem
export PATH=$GEM_HOME/bin:$PATH
export ANDROID_HOME=$HOME/Library/Android/sdk
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
only use google apis image do not usese play image
u will get list of avds
emulator -list-avds
emulator -avd Nexus_5_API_29 -writable-system (do not close terminal) (open a new terminal)
adb root
adb remount
copy mac host file to Downloads from /private/etc/hosts
adb push Downloads/hosts /system/etc/hosts
adb reboot
I am trying to reach the sqlite database on my device using the procedure described here: How can i see SQLite Database (No emulator)?
However, I keep on getting sqlite3 not found.
I assume I am meant to be entering the commands with the hash (#) sign at the start of the line.
I tried with it and got nothing.
Without it I get the error message.
The sqlite3.exe file is definitely there and in the path.
Do I have to install something?
Some manufacturers deliver the devices without sqlite being installed on them. You can copy the sqlite program though from a emulator to your device if the device has an arm processor.
Start the emulator and use the adb command from the platform-tools in android-sdk
adb pull /system/xbin/sqlite3
Mount the system partition of your device read/write after this tutorial:
http://android-tricks.blogspot.com/2009/01/mount-filesystem-read-write.html
Use the adb command to copy the sqlite3 file to your device
adb push sqlite3 /system/xbin/
After you reboot your device the sqlite3 command should work.
Edit (copy from linked page - in the case link becomes invalid). The instructions for step 2 are:
adb shell
su
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
"Replace /dev/block/mtdblock3 & /system with appropriate device path and mount point, as obtained from cat /proc/mounts"
Go to Play store --> search for Titanium Backup & install it
adb shell
su
cp /data/data/com.keramidas.TitaniumBackup/files/sqlite3 /system/xbin/
cd /system/xbin/
chmod 755 sqlite3
adbd reboot (just in case)
Enjoy the result
For those who, like me, couldn't use Sqlite3, I used a workaround for this:
cat srcfile> / mnt / sdcard / dstfile
With this you can put the files into an external .db manager.
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?
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 :
Copy system.img from the platform directory to your AVD directory.
Convert the amount of space you need to hex. For instance, if you need 500M, this is 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
Now you can just start the emulator with emulator -avd Galaxy_Nexus, and it'll use your changes
Update: 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.
Create new AVD, for instance example.avd
Copy system.img from android-sdk-linux/platforms/android-10/images
to ~/.android/avd/example.avd
Make system.img as writable and readable (either in the properties
or simply using terminal)
Run your AVD using command emulator -avd example
Remount your system as rw using adb shell mount -o rw,remount -t
yaffs2 /dev/block/mtd0 /system (to discover the partition use
command cat /proc/mtd)
Make your changes...
Now during the run of emulator find tmp emulator in
/tmp/android-<your_computer_name> with strange name like:
emulator-PQ7LgE and copy it in ~/.android/avd/example.avd
Delete system.img and rename copied tmp emulator into system.img
Close emulator
Delete cache.img, userdata.img and userdata-qemu.img from
~/.android/avd/example.avd
Run your emulator once again
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.
I had trouble finding the system.img file and AVD directory that F.X. posted about. On Mac you can find them here:
system.img: ~/Library/Android/sdk/system-images/android-19/default/
AVD Directory: ~/.android/avd/Nexus.avd/
I don't have enough reputation to add it as a comment, so I had to post it like this. Sorry.
use this command in terminal
cd /Users/NAME_USER/Library/Android/sdk/emulator # Move to emulator folder
sudo ./emulator -writable-system -avd NAME_AVD -partition-size 280 # Run avd by writable system
sudo adb root # Change to root
sudo adb remount # remount again
sudo adb shell
su
mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
change NAME_USER and NAME_AVD
F.X.'s answer does not work for me with Android API 19 and 21 on Windows as it stands. With the given parameters
emulator -avd <AVD> -qemu -nand system,size=0x<SIZE IN HEX>,file=<PATH/TO/system.img>
the system fails to mount the image. By looking at the kernel output I found out that it uses suspicious page size (2048) and two nonzero parameter values: extra size and "erase". These parameters are not documented anywhere, but you can see them in qemu's source code. What ended up working for me was
emulator -avd <AVD> -qemu -nand system,size=0x<SIZE IN HEX>,file=<PATH/TO/system.img>,pagesize=512,extrasize=0
With those parameters specified, "erase" gets set to 0 as well.
I was also surprised to find out that with these parameters the system is unable to boot to the graphical environment, but adb works.
The best way to do this is to use the following command:
<path-to-emulator-executable> -avd <AVD> -partition-size 512
As said here at https://justus.berlin/2015/02/make-persistent-changes-to-system-in-android-emulator/
Copying system.img into avd folder will work.
New year new solutions.
Just copy the system.img to your avd folder and rename the system.img to system-qemu.img
For me, copying C:\Android\sdk\system-images\android-22\android-tv\armeabi-v7a\system.img
to C:\Users\Neil Agarwal\.android\avd\Android_TV_1080p_API_22.avd\
and renaming it to system-qemu.img did the trick.
Please restart your avd after this.