Working with SD cards in the Android emulator

Mårten Österberg

Working with external storage in the Android emulator could be a little tricky and the documentation is not easy to find. I'll try to give a brief walk through of the steps needed to create a SD card image, mount the image in Linux, put content on it and use it in the emulator.

Creating a SD card image
In both the 1.1 and 1.5 version of the SDK there is a tool called mksdcard located in the SDK Install Dir/tools folder. Simply run

./mksdcard 128M my128MbCard

to create a 128Mb SD card with the name my128MbCard.

Mounting a SD card image in Linux
To be able to put content on to the card you can mount the card in Linux. It will then simply appear as a folder in the filesystem.
First make a directory in the /media folder:

sudo mkdir /media/mycard

Then mount the card as a loopback device:

sudo mount -o loop my128MbCard /media/mycard

Adding content to the card
With content we usually mean media content like images and videos. Images and videos are located in a folder called /dcim/Camera. You could of course add any content to the card. When you are done copying your files be sure to umount the card otherwise it will not be usable from the emulator.

sudo umount /media/mycard/

Using the card in the emulator
Google added something called Android Virtual Device (AVD) to the SDK 1.5. To create a new AVD using our newly created SDcard image run the following:

./android create avd --name myAVD --target 2 --sdcard my128MbCard

Target 2 means that we want to use the 1.5 API features in the device. Now we simply fire up the emulator and start using our content:

./emulator -avd myAVD

More information about the new SDK can be found here: SDK

Mårten Österberg
Consultant at Jayway

Tags: , , ,

32 comments ↓

#1 Kathryn on 04.29.09 at 15:49

Thanks for this tutorial!! :) It was very helpful.

#2 Faster start up of the Android Emulator « catairborne android development on 05.14.09 at 8:29

[...] 14, 2009 First of all, you may wish to have a look here, and setup a memory card in your project directory called my128MbCard if you want to use any of the [...]

#3 Elad on 06.03.09 at 1:43

What do you do if you don’t have linux?

#4 Mårten Österberg on 06.03.09 at 7:41

Hi Elad,

I don’t have much experience with the Android SDK on windows but I suppose you could still mount the iso file using a mount tool. This might be a good start: http://www.howtogeek.com/howto/windows-vista/mount-an-iso-image-in-windows-vista/

#5 Andy on 06.22.09 at 21:31

When I try to mount, it says
mount: -o loop: option not supported

what should i do

#6 sheff on 10.23.09 at 8:46

Hi. It was an useful article. Thanks

#7 Elbombardi on 12.23.09 at 15:56

Thanks budy!

#8 Jay on 02.16.10 at 6:03

I figured this out on Windows, in case anyone needs that info. Go to \http://www.androidref.com\ and look for \How to create an SD card, store a contact photo, and display the photo on the handset.\.

#9 channa on 03.29.10 at 12:30

Hey,
For the last steps of creating AVD, Can we use the -sdcard option for the emulator?

./emulator -sdcard my128MbCard .

Regards,
Channa

#10 Vaibhavdi on 04.02.10 at 9:29

Hay, Thanks buddy steps are working as it is…

#11 demonrodd on 04.20.10 at 15:00

Thanks a lot man….it helped me to access the sdcard in linux……i am using the 2.1 version of the SDK……though the last two steps for emulator are not needed if you are using eclipse for developing apps…..in eclipse go to
Run->Debug Configurations->Target->Addtional Emulator command line options, type the following

-sdcard /the path where we have created the my128MbCard/my128MbCard

once again thanks a lot

#12 Le Repaire du Sanglier des Ardennes » Blog Archive » [Android] Environnement de développement on 05.08.10 at 16:17

[...] http://blog.jayway.com/2009/04/22/working-with-sd-cards-in-the-android-emulator/ http://wiki.frandroid.com/wiki/DevGuide/tutorials/hello-world.html http://www.android.encke.net/ [...]

#13 Matthew on 05.16.10 at 9:52

Great way to transfer files in an emulator!! I’m using Android 2.1, waiting for the Google I/O conference news! This is wonderful!

#14 Working with Android SD Cards image on Mac « 2cupsOfTech on 05.19.10 at 10:00

[...] an sd card and connect that sd card image with the an android emulator. The post by Jayway team (http://blog.jayway.com/2009/04/22/working-with-sd-cards-in-the-android-emulator/) helped me to get started but those instructions are linux specific and didn’t work for me on [...]

#15 2cupsoftech on 05.19.10 at 10:05

@ #5 Andy, I understand you are using a Mac like myself. See this:
http://2cupsoftech.wordpress.com/2010/05/19/working-with-android-sd-cards-image-on-mac/

#16 UltraBlue on 05.28.10 at 17:03

thanks. that was helpful

#17 poonkodinatarajan on 06.11.10 at 8:25

hi

this is very useful and working well.thank you

#18 Guille on 07.06.10 at 17:49

very useful paper.. Thank you..
A question…
The sdcard format is FAT. Is possible to change this format to ext2 or ext3 format ?
Thanks in advance!!

#19 Rakesh on 08.30.10 at 9:52

Thanks a lot for sharing.

But i want to make one small application which will check status of my External storage,Add files or pictures into External storge ,and read that data from Gallery folder of my emulator.

Can u help me to accomplish my app.

Thanks

#20 Creating folder on the sdcard in the android avd emulator | ChrisDoesDev.com on 09.03.10 at 12:01

[...] can use the DDMS perspective on Eclipse (blog.jayway.com/2009/04/22/working-with-sd-cards-in-the-android-emulator/) to view the sd card on the running emulator, and can copy files to the root folder, but I [...]

#21 Wajid on 11.23.10 at 3:27

I am using Android SDK by Eclipse on windows 7 environment. How can i create folder in somelocation of SD card?

#22 Vivek on 02.27.11 at 14:34

Crisp Info!

#23 Lisvid com on 02.28.11 at 6:57

can you explain for windows

#24 vermasque on 03.18.11 at 6:13

Helpful explanation. I made a Bash script for testing my Android app that does the things above: https://github.com/vermasque/song-alarm/blob/master/tests/make_sdcard.sh

#25 andria on 05.17.11 at 9:39

Hi

Do you know how to make a sdcard with partition in the sdcard?

Thanks

#26 ramiz on 07.22.11 at 12:30

while creating itself select sd card .its simple.then using file explorer from window->view you can store and retrive data on sdcard!!!!

#27 Working with SD cards in the Android emulator « Savin on 08.06.11 at 17:12

[...] http://blog.jayway.com/2009/04/22/working-with-sd-cards-in-the-android-emulator/ [...]

#28 P-a on 08.30.11 at 18:31

In OSX, just name the image .iso and type ‘open mycard.iso’ and it will be mounted and available in Finder

#29 Matías Romano on 09.15.11 at 17:44

Thanks !!!
I will try it and i wil tell you about the results.

#30 Krishna on 10.06.11 at 22:53

Hi
If you are using Eclipse it is very easy to create SD card at the time of creating a new virtual device.

#31 GK on 10.06.11 at 22:56

Here is the link used for me:
http://androiddevelopement.blogspot.com/2011/09/how-to-emulate-sd-card-with-android.html

#32 Sarita on 01.10.12 at 12:30

Thanks Buddy ! It is working. By the way what is the idea behind mount and unmount ? If anyways we are going to unmount then why mount ?

Leave a Comment