84

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Alex Pritchard
  • 4,260
  • 5
  • 33
  • 48
  • @Alex Pritchard: You probably do not need a 1024M fake SD card. Try 32M instead and see if you have better luck. – CommonsWare Oct 07 '10 at 13:11
  • @CommonsWare Alas, the 32M SD card still fails to create. :( – Alex Pritchard Oct 07 '10 at 19:50
  • @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 Oct 07 '10 at 20:28
  • @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 Oct 07 '10 at 23:35
  • @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 Oct 07 '10 at 23:41
  • Hooray! ia32-libs did the trick! – Alex Pritchard Oct 08 '10 at 01:31

18 Answers18

101

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.

Alex Pritchard
  • 4,260
  • 5
  • 33
  • 48
  • 1
    Thanks, ubuntu 12.04 x64, it resolved the problem. I'd only remark that these ia32-libs are 260mb approx – yetanothercoder Jul 24 '12 at 12:59
  • 43
    Yes! I found the way without all those awful 240 dependency packages! Instead of `ia32-libs` install `libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386`. Kudos to this guy, who saved my (and hopefully others) computer from all the garbage: http://stackoverflow.com/a/10473415/998772 P.S. I'm using Linux Mint 13 – pavel_kazlou Sep 20 '12 at 20:48
  • 4
    On Fedora, `dnf install glibc.i686 libstdc++.i686` – Dominic Cleal May 01 '14 at 08:32
  • thank you. I use Ubuntu 14.04 LTS amd and it solves the problem. I installed separated packages like @pavel_kazlou suggested – Joao Polo Jan 04 '16 at 15:31
  • Amazing that this is still needed in 2017(!) when development is mostly done on x86-64 machines... – nimrodm Mar 27 '17 at 19:21
  • 1
    @nimrodm I am continually surprised at activity on this post (my most popular SO post to date, hah). – Alex Pritchard Mar 28 '17 at 18:44
  • Facing same issue for windows 10. – shaby Dec 12 '19 at 07:02
80

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
phoenix
  • 7,988
  • 6
  • 39
  • 45
GeekLei
  • 991
  • 7
  • 8
  • I've installed the SDK manually (without Android Studio), and this worked for me. – Cristian Todea Jan 21 '17 at 03:45
  • 1
    Besides that, I had to rename the ~/Android/Sdk/emulator/lib64/libstdc++/libstdc++.so.6 and libstdc++.so.6.0.18 to something else in order to make the emulator run. I could only get it to run without opengl tough. --------------- ./emulator @Nexus_4_API_23 failed to create drawable getGLES2ExtensionString: Could not create GLES 2.x Pbuffer! Failed to obtain GLES 2.x extensions string! Could not initialize emulated framebuffer emulator: ERROR: Could not initialize OpenglES emulation, use '-gpu off' to disable it. – Francisco Junior Jun 02 '17 at 19:11
  • 1
    Bingo. Ubuntu 17.04. – mez.pahlan Oct 21 '17 at 14:57
22

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

mfontanini
  • 21,410
  • 4
  • 65
  • 73
cynicholas
  • 221
  • 2
  • 4
  • 1
    Thank you for contributing an answer. Stack Overflow provides formating to enhance the readability of your answer. You can use code formatting to identify the shell command and set it apart from your other text. – this.josh Apr 28 '11 at 18:23
  • Works, but this results in `.txt`, `.xml` files etc having executable permission... would be nice to know the individual files involved – funkybro Nov 30 '16 at 11:41
10

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++
Paolo Rovelli
  • 9,396
  • 2
  • 58
  • 37
6

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).

paulsm4
  • 114,292
  • 17
  • 138
  • 190
5

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
Lugty
  • 51
  • 1
  • 1
4

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.

Larry_C
  • 316
  • 1
  • 9
4
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++/**
Prasad Khode
  • 6,602
  • 11
  • 44
  • 59
Kumar Ayush
  • 103
  • 1
  • 4
4
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 :)

bstpierre
  • 30,042
  • 15
  • 70
  • 103
imon_iut
  • 51
  • 1
3

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

agent-j
  • 27,335
  • 5
  • 52
  • 79
rubenj
  • 118
  • 1
  • 6
2

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.

Andrew Paul Simmons
  • 4,334
  • 3
  • 31
  • 39
1

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

CosmicCat
  • 31
  • 2
1

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

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

SerVel
  • 11
0

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 *
Dharman
  • 30,962
  • 25
  • 85
  • 135
-1

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

-1

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.

Jomia
  • 3,414
  • 10
  • 46
  • 63
-1

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.

shaby
  • 1,301
  • 1
  • 15
  • 17