I'd like to create an Android Virtual Device against which I can test recent issues with writing to external SD cards. I would expect the external sd card to be found at location like "/storage/extSdCard/DCIM/" on the AVD's file system. Any suggestions on how I can accomplish this?
To add removable storage to your AVD use:
~/Android/android-sdk/tools/mksdcard [memory size] [output file]
to create SD card image.
Then pass it in Advanced AVD Settings dialog: SD card -> External file
DONE :)
You can learn more about the mksdcard tool here:
https://developer.android.com/studio/command-line/mksdcard
You can open Android Device Monitor which is the Android symbol next to the SDK Manager. Once opened you can see the files using the file explorer and here you can create the required folders/path for using the external SD card.
There is a chance that when you try and create a folder it will say it is read only, if this happens open up command prompt and using adb shell input these commands:
mount -o rw,remount rootfs /
chmod 777 /mnt/sdcard
exit
These commands are from this link
On macOS Mojave 1.14.3 with Android Studio 3.3.1 I found the path to be slightly different.
Create a 128 Gb sdcard:
~/Library/Android/sdk/tools/mksdcard 128G sdcard.ini
Related
I wanted to add a file to the sd card of the android emulator but i receive this error:
Failed to push selection: Read-only file system
What shall I do? I am an Android beginner and still learning how to use the terminal and all that stuff. So please, can someone give me a step-by-step tutorial and not just another link?
This is a tutorial regarding creation of SD Card. While creating the current SD card, you may not have given it write permission. Follow the steps in that tutorial and you will be able to upload image to SD card.
EDIT
Step1: ...tools>android create avd -n myemulator -t 8
Step2: ...tools>mksdcard -l e 512M mysdcard.img
Step3: ...tools>emulator -avd myemulator -sdcard mysdcard
I have created an Android emulator (Android Virtual Device), but I am unable to find out the SD card I have built during creation of this.
How can I find the SD card and its content and also how to install APK files to the AVD?
switch to DDMS perspective
select the emulator in devices list, whose sdcard you want to explore.
open File Explorer tab on right hand side.
expand tree structure. mnt/sdcard/
refer to image below
To install apk manually:
copy your apk to to sdk/platform-tools folder and run following command in the same folder
adb install apklocation.apk
I have used the following procedure.
Procedure to install the apk files in Android Emulator(AVD):
Check your installed directory(ex: C:\Program Files (x86)\Android\android-sdk\platform-tools), whether it has the adb.exe or not). If not present in this folder, then download the attachment here, extract the zip files. You will get adb files, copy and paste those three files inside tools folder
Run AVD manager from C:\Program Files (x86)\Android\android-sdk and start the Android Emulator.
Copy and paste the apk file inside the C:\Program Files (x86)\Android\android-sdk\platform-tools
Go to Start -> Run -> cmd
Type cd “C:\Program Files (x86)\Android\android-sdk\platform-tools”
Type adb install example.apk
After getting success command
Go to Application icon in Android emulator, we can see the your
application
These days the location of the emulated SD card is at /storage/emulated/0
On linux sdcard image is located in:
~/.android/avd/<avd name>.avd/sdcard.img
You can mount it for example with (assuming /mnt/sdcard is existing directory):
sudo mount sdcard.img -o loop /mnt/sdcard
To install apk file use adb:
adb install your_app.apk
DDMS is deprecated in android 3.0. "Device file explorer"can be used to browse files.
Drag & Drop
To install apk in avd, just manually drag and drop the apk file in the opened emulated device
The same if you want to copy a file to the sd card
if you are using Eclipse. You should switch to DDMS perspective from top-right corner there after selecting your device you can see folder tree. to install apk manually you can use adb command
adb install apklocation.apk
I have used the following procedure.
Android Studio 3.4.1
View>Tool Windows>Device File Explorer
//in linux
// in your home folder .android hidden folder is there go to that there you can find the avd folder open that and check your avd name that you created open that and you can see the sdcard.img that is your sdcard file.
//To install apk in linux
$adb install ./yourfolder/myapkfile.apk
Adding to the usefile DDMS/File Explorer solution, for those that don't know, if you want to read a file you need to select the "Pull File from Device" button on the file viewer toolbar. Unfortunately you can't just drag out, or double click to read.
I am trying to develop a simple pygame with Ubuntu Linux 11.10 for my Motorola android phone. I am having trouble getting the "adb push" command to work. I get an failed to copy 'foo.txt' to '/media/MOT': No such file or directory error message. What am I doing wrong?
Here is what I tried so far:
The phone's SD card is mounted at /media/MOT/ and I am able to ls, create a folder and delete a folder in it.
user#linuxlappy:~$
user#linuxlappy:~$ cd /media/MOT/
user#linuxlappy:/media/MOT$ ls
Android burstlyImageCache burstlyVideoCache data DCIM download gstomperdemo LOST.DIR slacker temp.apk
user#linuxlappy:/media/MOT$ mkdir writetest
user#linuxlappy:/media/MOT$ rmdir writetest/
The file that I am trying to copy is foo.txt in my /home/user/ directory
user#linuxlappy:/media/MOT$ cd /home/user/
user#linuxlappy:~$ ls foo.*
foo.txt foo.txt~
I enabled USB debugging on the phone with:
Settings > Applications > Development > USB debugging.
I believe I have adb installed correctly, I am able to list the phone with adb devices.
user#linuxlappy:~$ adb devices
List of devices attached
0910E8201700B017 device
When I try to push a simple text file to the SD card I get this error message.
user#linuxlappy:~$ adb push foo.txt /media/MOT
failed to copy 'foo.txt' to '/media/MOT': No such file or directory
user#linuxlappy:~$
The phone's SD card is mounted at /media/MOT/
Based on your terminal output, it is mounted on your desktop Linux environment as /media/MOT. In which case, to copy files to it, you use cp.
Using adb push, you need to use the path where the external storage resides on the phone. A common spot is /mnt/sdcard/, though it may vary. Also, bear in mind that, depending on your phone, external storage may not be available while you have it mounted as a volume on your desktop Linux environment.
For debugging purposes, I wanted to have a couple of mp3 files located somewhere "in" my android emulator. Is there anyway to directly push files from my OS file system to the storage system of android?
If so, which directory does android keep audio files?
if not, how can I access an SD card via emulator?
[update2]: The problem in update1 solved. Should use adb push.
[update1]: I followed kgiannakakis's advice to create an sdcard for my avd. However, I got Permission denied error when I try to create new directory inside it.
$ cd sdcard
$ ls
LOST.DIR
$mkdir musics
mkdir failed for musics, Permission denied
$ su mkdir musics
su: uid 10016 not allowed to su
You can find directions for emulating an SD card here.
I believe that the easiest way to copy files to the SD card is to use the adb utility.
See here for a more advanced solution.
Regarding instructions at http://android-er.blogspot.com/2009/10/create-sd-card-in-android-emulator-and.html on creating the 'pictures' folder, you can run the same commands from the adb shell, instead of running them from inside the emulator.
So get a command line at e.g. C:\Program Files (x86)\Android\android-sdk-windows\platform-tools (on 64bit windows), and run adb shell.
Then you can run the same commands:
#cd sdcard
#mkdir pictures
and create the directory successfully with no permission denied error.
Following same instructions, in DDMS I had to browse to \mnt\sdcard to find the SD card volume.
I feel a bit blind developing on an emulator for Android and not being able to see the file system on the AVD (.img).
Is there a way to mount it in Windows or Linux, so that I could at least see the file listing and maybe contents?
Bonus if it's mounted with write permissions as well.
Thank you.
You can just mount the device in Linux:
sudo mount -o loop ~/.android/avd/<myvirt>/sdcard.img <destdir>
How about "adb shell"?
This will give you a root shell (on the emulator)..
For MacOS X users:
$ hdiutil attach ~/.android/avd/Samsung_Nexus_S.avd/sdcard.img
For Windows, I just ran across the ImDisk Virtual Disk Driver
Install this utility, and you can then mount sdcard.img. There's a nice tutorial here
Yes, they can be mounted. Under Ubuntu you can mount sdcard.img via vfat and system.img and userdata-qemu.img via yaffs2. See also: "Whats Android file system ??".
Note that the file system yaffs2 is not included in the standard Ubuntu kernel. Thus, in case of Ubuntu, you have to build your own kernel with yaffs2 support before you are able to mount the system.img and the userdata-qemu.img. Alternatively, you can also take a look at the yaffs2utils which allow you to extract files from yaffs2 images or to create new image files. The advantage is that you do not have to build your own kernel for using these tools.
Another option would be to use the File Explorer in DDMS (Eclipse SDK), you can see the whole file system there and download/upload files to the desired place. That way you don't have to mount and deal with images.
I tried mounting and it's cumbersome, for example if the emulator is running you can't do it. Plus you would need to mount each image if you want to see all contents.