84
votes

I see a lot of posts about writing to the SD card, but I believe my problem is different. I am unable to create the SD card during the process of building an AVD.

I initially tried to use the Android SDK and AVD Manager to do this, selecting
Name: my_avd
Target: Android 2.2 - API Level 8
SD Card: Size: 1024 MiB
Skin: Built-In: Default (HVGA)
Hardware: Property: Abstracted LCD Density, Value: 160

This pops up a window with the message:
"Result of creating AVD 'my_avd':
Error: Failed to create the SD card."

I tried to repeat the process from the command line, receiving a similar error:

alex@alex-desktop:~$ android create avd -n my_avd -t 1 -c 1024M
Android 2.2 is a basic Android platform.
Do you wish to create a custom hardware profile [no]no
Error: Failed to create the SD card.

Attempting to follow instructions for using mksdcard was equally unproductive; I think my basic lack of linux experience may be causing me a problem here. When I try to use mksdcard, it just reports that it cannot find the file or directory. Is the mksdcard tool available for use this way in linux?

alex@alex-desktop:~$ mksdcard 1024M ./sdcard.iso
bash: /home/alex/android-sdk-linux_x86/tools/mksdcard: No such file or directory
alex@alex-desktop:~$ sudo android create avd -n my_avd -t 1 -c 1024M

I've added the android tools directory to my PATH variable, but I feel like there is obviously something else I'm missing. Perhaps some kind of access rights?

Attempting to run the android command with sudo did not seem to help either:

alex@alex-desktop:~/android-sdk-linux_x86/tools$ sudo ./android create avd -n my_avd -t 1 -c 1024M
Android 2.2 is a basic Android platform.
Do you wish to create a custom hardware profile [no]no
Error: Failed to create the SD card.

I even tried installing Eclipse and the ADT plugin and running the manager from there to no avail. Any tips would be most appreciated. Advanced warning that I am somewhat of a novice Linux user, so even if it seems like a no-brainer obvious thing to check, I could still have missed it.

18
@Alex Pritchard: You probably do not need a 1024M fake SD card. Try 32M instead and see if you have better luck. - CommonsWare
@CommonsWare Alas, the 32M SD card still fails to create. :( - Alex Pritchard
@Alex Pritchard: That's pretty strange. The images are created in the same directory as the rest of the AVD (~/.android/avd/whateveryoucalledit/), so I can't quite fathom how you can create an AVD but not an AVD with an SD card. - CommonsWare
@CommonsWare I've been doing a bit more reading around and think I might have found something. I suspect there may be some problem because I am using 64-bit linux install and may need to install the ia32-libs. I am going to try this when I return home and see if it helps. - Alex Pritchard
@Alex Pritchard: Yeah, I believe that you need those. Surprised it runs at all without them, actually. I had to go through some gyrations to get Android to run on my 64-bit Ubuntu setup, though that was long enough ago that I forget the details. - CommonsWare

18 Answers

101
votes

So I found the problem. I was using a 64-bit Linux install, which did not have the ia32-libs package installed by default. The mksdcard utility will not run without this package. After installing it, I was able to build the AVD without a problem using the AVD manager.

80
votes

On Ubuntu 16.04 LTS x64, using Android Studio 2.1 (also tested on 2.3.3), run from a terminal:

sudo apt-get install lib32stdc++6
22
votes

I had the same error like you and I have just solved it, so maybe it can help you (though I don't think your error is caused by the same problem like me).

I found that all tools in ../tools don't have the permission to excute, so I used

chmod -R 777 ../tools

from the command line and it finally works

10
votes

As others have already written, the problem is that your Linux distro is a 64-bit one and, at present, Android Virtual Device (AVD) needs the x86 library to work correctly.

Someone has suggested to install ia32-libs. However, in Ubuntu 14.04 LTS you won't find this library. I solved using these alternative libs: lib32z1, lib32ncurses5, lib32bz2-1.0 and lib32stdc++.

sudo apt-get update
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++
6
votes

I just encountered the same problem. NONE of the SDK tools will run on 64-bit Ubuntu without installing ia32-libs (EXAMPLE: sudo apt-get install ia32-libs).

5
votes

In elementary OS and ubuntu, the solutions was to install the following packages

sudo apt-get install lib32ncurses5 lib32z1
sudo apt-get install libgcc1:i386
4
votes
alex@alex-desktop:~$ mksdcard 1024M ./sdcard.iso
bash: /home/alex/android-sdk-linux_x86/tools/mksdcard: No such file or directory
alex@alex-desktop:~$ sudo android create avd -n my_avd -t 1 -c 1024M

I have found this problem & i find a way first:

cd /home/alex/android-sdk-linux_x86/tools/

then write this:

sudo chmod 755 mksdcard
mksdcard 1024M ./sdcard.iso
sudo android create avd -n my_avd -t 1 -c 1024M

it should work :)

4
votes

If you are using Kali, Debian Jessie (or Ubuntu 13.10+), try

sudo apt-get install lib32stdc++6

instead of the ia32-libs mentioned above.

4
votes
sudo apt-get install lib32stdc++6

After this you might get following errors

Cannot launch AVD in emulator.
Output:
libGL error: unable to load driver: i965_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: i965
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
X Error of failed request:  GLXBadContext
  Major opcode of failed request:  154 (GLX)
  Minor opcode of failed request:  6 (X_GLXIsDirect)
  Serial number of failed request:  49
  Current serial number in output stream:  48
libGL error: unable to load driver: i965_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: i965
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
X Error of failed request:  GLXBadContext
  Major opcode of failed request:  154 (GLX)
  Minor opcode of failed request:  6 (X_GLXIsDirect)
  Serial number of failed request:  49
  Current serial number in output stream:  48
libGL error: unable to load driver: i965_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: i965
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
emulator: WARNING: VM heap size set below hardware specified minimum of 228MB
X Error of failed request:  BadValue (integer parameter out of range for operation)
emulator: WARNING: Setting VM heap size to 384MB
  Major opcode of failed request:  154 (GLX)
  Minor opcode of failed request:  24 (X_GLXCreateNewContext)
  Value in failed request:  0x0
  Serial number of failed request:  33
  Current serial number in output stream:  34
QObject::~QObject: Timers cannot be stopped from another thread

Use these 3 commands to solve those

mv ~/Android/Sdk/tools/lib64/libstdc++/libstdc++.so.6{,.bak}
mv ~/Android/Sdk/tools/lib64/libstdc++/libstdc++.so.6.0.18{,.bak}
ln -s /usr/lib/libstdc++.so  ~/Android/Sdk/tools/lib64/libstdc++/**
3
votes

Also had this problem and after installing the i386 package I was able to create a SD-card for my Android emulator I had to do two steps

sudo apt-get update
sudo apt-get install ia32-libs

After this was finished, I was able to create an emulator with a SD-card attached

2
votes

I had a different problem: platform-tools was in my path but tools was not. So, everything worked except that the SDCard image was not created. There was no notice of this when I created the avd in eclipse and the virtual device was created with a really small sd card causing it to constantly throw the media not available error on app install.

1
votes

I had a different problem using 32bit Ubuntu. When i tried to run mksdcard by hand, I was getting a file not found error.

The problem was open-jre/jdk. I installed oracle java and the problem was fixed. Unfortunately you can no longer install oracle java through apt/synaptic and have to jump through some extra hoops:

https://github.com/flexiondotorg/oab-java6

1
votes

On debian testing, when i tried to run ./tools/mksdcards, i received the error:

error while loading shared libraries: libstdc++.so.6: 
cannot open shared object file: No such file or directory

Installing lib32stdc++6 resolves the problem, and was possible to create the avd.

0
votes

MyOS is Oracle Unbreakable Linux 6 - to solve this issue I had to install libstdc++-4.4.6-3.el6.i686 package.

0
votes

After a lot of installing and not getting any result I found this and it worked.

This happens because some executable files in sdk/tools cannot be executed. Go to your Android Studio and Android SDK folders and make all directory and files executable by this command:

chmod +x -R *
-1
votes

Try moving the android sdk folder to home folder. It works.

-1
votes

I had the same problem. After troubleshooting, I came to know that, it was because of my Windows is 32bit and my mksdcard is compatible with 64 bit only. Then I just copied a mksdcard of 32 bit to tools folder, and deleted the older one. It solved my problem.

-1
votes

For the people who faced the same issue on windows. For me it was because mksdcard.exe tool was unable to run successfully. Some SDK tools such as mksdcard.exe require Microsoft Visual C++ runtime. So go to your System properties and check your System type:

enter image description here

Then based on your system type,(for me it was x64) download/update the latest Microsoft Visual C++ Redistributable for Visual Studio 2019 from the link https://visualstudio.microsoft.com/downloads/

enter image description here

After installing Microsoft Visual C++, my problem was fixed. I was able to create AVD successfully.