Thursday, May 31, 2012

Solution: Android INSTALL_FAILED_INSUFFICIENT_STORAGE error


The INSTALL_FAILED_INSUFFICIENT_STORAGE error is the bane of every Android developer's life. It happens regardless of app size, or how much storage is available. Rebooting the target device fixes the problem briefly, but it soon comes back. There are hundreds (if not thousands) of message board posts from people asking why the problem occurs, but the folks at Google are frustratingly silent on the issue.



There is a simple workaround. If your test device is running Android 2.2 or later then add the android:installLocation attribute to your application's manifest file, with the value " preferExternal ". This will force the app to be installed on the device's external storage, such as a phone's SD card.



For example:




<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.andrewsmith.android.darkness"
android:installLocation="preferExternal"



This is more of a band-aid than a fix, and it may not be ideal if you want your finished app to install on the device's internal memory. But it will at least make the development process a lot less frustrating.


Source: Tips4all

19 comments:

  1. You need to increase the Android emulator's memory capacity, there are 2 ways for that:

    1- Right click the root of your Android Project, go to "Run As" then go to "Run Configurations..." locate the "Android Application" node in the tree at the left, then select your project and go to the "Target" tab on the right side of the window look down for the "Additional Emulator Command Line Options" field (sometimes you'll need to make the window larger) and finally paste "-partition-size 1024" there. Click Apply and then Run to use your emulator.

    2- Go to Eclipse's Preferences, then Select “Launch” Add “-partition-size 1024” on the “Default emulator option” field, then click “Apply” and use your emulator as usual.

    ReplyDelete
  2. Thanks for posting this question. I have some additional insights that may help some developers.

    I am debugging my application on a device (not the emulator). The device has 21MB free on /data (as revealed by "df" when doing "adb shell") and my app is only 5MB. However, I did find that if I deleted other apps on the device (without rebooting the phone or restarting adbd), INSTALL_FAILED_INSUFFICIENT_STORAGE would go away for a while, then come back.

    So seems that debugging my 5MB app requires more like 20MB of space in /data, and in addition something was leaking each time I debugged my app.

    So I did "adb shell" and listed the ENTIRE /data directory with

    cd /data
    ls -a -l -R


    and looked at the 5000-line output to see where all the space was going.

    I discovered vast quantities of wasted space on my device in the /data/klog directory in the form of old log files from months-old debugging sessions.

    These were not my log files: they were created by some part of the Android infrastructure.

    I deleted them and instantly saved 58MB which was not attributed in the Settings app to any particular app. I have a small device so 58MB is very significant (about 40%).

    So far, I have not gotten INSTALL_FAILED_INSUFFICIENT_STORAGE again after many runs. Let's hope that was the real issue, though the OP suggests that his device had plenty of space (but didn't say how much).

    Hopefully some of you will also be able to escape INSTALL_FAILED_INSUFFICIENT_STORAGE by periodically deleting /data/klog/*

    Or, you can at least do the ls -a -l -R in /data to see where all your space is going, if indeed there is really some (hidden) space issue.

    ReplyDelete
  3. Samsung Galaxy Ace advertises 158MB of internal storage in its specifications, but the core applications and services consume about 110MB of that (I used the task manager on the device to inspect this). My app was 52MB because it had a lot of assets, once I deleted some of those down to 45MB the app managed to install without a problem. The device was still alerting me that internal storage is almost full and I should uninstall some apps, even though I only had one app installed.

    Update: After installing a release version of the .apk bundle and then uninstalling it, my device displays 99MB of free space, so it might be debugging information cluttering up the device after all. See Louis Semprini's answer.

    ReplyDelete
  4. I came across this question because I was getting this error using the Sideload Wonder Machine to install apps to my actual phone. I found the problem was that I had multiple .apk files in the /payload directory. I thought this was something that was supported, but when I removed all but one .apk, the error went away.

    ReplyDelete
  5. If you're using a real device, you've simply ran out of internal memory. Just go to Android settings > applications, and move some apps to the SD card or uninstall some apps.

    If you're using the emulator see Oscar's Answer.

    ReplyDelete
  6. A related issue on the emulator is when there is no space left in the /data partition

    For example,

    % adb shell df
    Filesystem Size Used Free Blksize
    /dev 252M 32K 252M 4096
    /mnt/asec 252M 0K 252M 4096
    /mnt/obb 252M 0K 252M 4096
    /system 154M 154M 0K 4096
    /data 64M 57M 6M 4096
    /cache 64M 1M 62M 4096


    Here a sample view of the /data/app directory:

    % adb shell ls -l /data/app
    -rw-r--r-- system system 19949 2011-10-12 17:09 CubeLiveWallpapers.apk
    -rw-r--r-- system system 27670 2011-10-12 17:09 GestureBuilder.apk
    -rw-r--r-- system system 34341 2011-10-12 17:09 SoftKeyboard.apk
    -rw-r--r-- system system 20151 2011-10-12 17:09 WidgetPreview.apk


    I removed the extra apk files. It seems upon every install you get a new apk file. Just remove extra apk files

    For example,

    adb shell rm /data/app/com.brooklynmarathon.calendarapi2-1.apk

    ReplyDelete
  7. I came across the same error when I tried to batch install about 50 apps in sd card directory using adb shell after a full ROM update.

    for x in *.apk; do pm install -r $x; done


    Some of them installed, but many failed with the error INSTALL_FAILED_INSUFFICIENT_STORAGE. All the failed apps had space in their name. I batch renamed them and tried again. It all worked this time. Did not do reboot or anything. May be this is not the problem you guys are facing, but this might help someone searching with the same problem as I faced.
    Thanks
    tN

    ReplyDelete
  8. Make sure you don't connect your android device with usb while trying to run the emulator

    ReplyDelete
  9. If you are running your application on an emulator, and if this problem persists, check your notification manager. If it shows you an icon and notification about "Phone memory is full", that means you have already installed so many applications on your emulator. Uninstall several applications which you don't want currently from "Settings >> Manage Application >> Select Application >> Uninstall".
    That Set.
    Now re-run the program.

    ReplyDelete
  10. workaround:

    compile as 2.1 without android:installLocation="preferExternal"
    OK?
    compile as 2.2 including android:installLocation="preferExternal"

    This will still install on sdk <8 (xml tag is ignored ++)

    ReplyDelete
  11. I too faced the same problem and i did a "Factory data reset" and it worked fine after that.

    ReplyDelete
  12. I didn't have root access on my phone, and am unprepared for my app to be installed on the sd card. 15M of space available on /data/ and my application is under 2M.

    For a while I got by; cleaning the eclipse project and restarting the phone, but eventually that stopped working (probably after an update).

    Cleaning my application cache has solved the problem for me and doesn't require a restart of the phone or uninstallation of the app.

    There are applications on the market which you can use to clear the cache of multiple applications at once. Search for "clean".

    ReplyDelete
  13. Tried the following:


    Restarted my device
    Deleted previous APK
    Rebuild my APK
    Uninstall my previous copy in the device
    Reinstall


    Check if it works the same with you.

    ReplyDelete
  14. As this issue still exists, I thought I'd add something to Oscar's answer for development purposes. If you're not using the eclipse plugin or for whatever reason you don't have the source, but just the .apk, you can increase the partition size from the command line using the same option when you launch the emulator:

    emulator -avd -partition-size 1024

    This option is not documented at developer.android.com afaik, so I thought I'd post it here so people might find this solution.

    ReplyDelete
  15. a bit time consuming - but should work in any case:
    install a file manager like adao on your phone.

    connect via usb and enable usb storage. copy the apk from your local build to the phone (you might need to allow unknown sources under application settings).

    then just tap the apk and android will install it.
    like I said it's time consuming - but might be faster than rebooting every now and then.

    ReplyDelete
  16. Emulator solution

    Open your .Android directory. Usually in your home directory. Then go to avd and then open the directory that has the name of the avd you would like to change.

    Now edit the config.ini file and add the following line or modify the following line:

    disk.dataPartition.size=1024

    Where 1024 is the size you would like to use in MB. Save the file and then start your emulator with wipe user data checked. Your emulator should now have the new size.

    ReplyDelete
  17. In my case it got fixed by increasing the extended memory of eclipse, by changing the value of -Xmx768m in eclipse.ini

    ReplyDelete
  18. The solution is simple.

    Open up the AVD Manager. Edit your AVD.

    Down in the hardware section, there are some properties listed with "New..." and "Delete" to the right of it.

    Press New. Select Data Partition size. Set to "512MB" (the MB is required). And you're done. if you still get issues, increase your system and cache partitions too using the same method.

    It's all documented right here:
    http://developer.android.com/guide/developing/devices/managing-avds.html

    ReplyDelete
  19. I had added an additional line to the application's manifest file, which is android:installLocation="preferExternal". by using this line it forces to install the app to the external storage. see the example below,

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.nasir.phonegap"
    android:installLocation="preferExternal" >

    ReplyDelete