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.
I have solved it by including
android:installLocation="auto"
inside<manifest>
tag in AndroidManifest.xml file.This is only a temporary workaround and not a real fix.
After having this happen to me and not being pleased with the current responses I went to work trying to figure it out from the AOSP source. I have found a REAL solution.
Explanation
First off, a bit of (simplified) background on how Android installs and updates
The issue that most of us are having happens when the application is updated, but deleting of the old APK fails. Which itself does not yet cause the update to fail, but it does cause there to be two APK files in
/data/app
.The next time you try to update the app the system can't move its temporary file because neither (1.apk) nor (2.apk) are empty. Since File#renameTo(File) doesn't throw an exception but instead returns a boolean PackageManager, it doesn't have any way to tell why it returns INSTALL_FAILED_INSUFFICIENT_STORAGE even though the failure had nothing to do with the amount of free space.
Solution
Run:
OR
Uninstall the app
Use your favorite method to delete BOTH:
Make sure nothing else blocks future installs in a similar way. In my case I had a
/data/app-lib/<full.package.name>-1
directory lingering around! In this case, an install to the SD card worked, and a subsequent move to internal memory, too. (Creating/data/app-lib/<full.package.name>
without the-1
ending.)Why other "solutions" worked
The code for installing to external storage is significantly different which does not have the same problems
Uninstalling the app only deletes one version of the APK file in
/data/app
. That's why you can reinstall it once, but not update it.The amount of free space in an emulator isn't really relevant when this bug occurs
If you're using a real device, you've simply run 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 RacZo's answer.
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.
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 21 MB free on
/data
(as revealed by "df" when doing "adb shell") and my app is only 5 MB. 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 and then come back.So it seems that debugging my 5 MB app requires more like 20 MB 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 withAnd I 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 58 MB which was not attributed in the Settings app to any particular app. I have a small device so 58 MB 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.The following helps:
Open a shell to the device
Navigate to the temp directory where the incoming APK is first copied
List the available files and delete as desired
This has been reliable for me so far on an actual device.
EDIT: This turned out to be not as reliable a solution as the one above.
I tried a number of the solutions. Nothing really helped. Finally I found an app called SD Maid. That helped.
It says the functionality is limited on unrooted devices. Mine is rooted so it would be good to see hear from people effective it is in those scenarios and if it was just a fluke that it worked for me (it is an unpredictable problem anyway).
NOTE: I have nothing to do with the app. Just found it with a search.