Solution to INSTALL_FAILED_INSUFFICIENT_STORAGE error on Android [closed]

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 first time an app is installed:

  1. The APK file is saved as

    /data/app/<full.package.name>-1.apk  (1.apk)
    

When the app is to be updated:

  1. The updated APK file is saved as:

    /data/app/<full.package.name>-2.apk (2.apk)
    
  2. The first version (1.apk) gets deleted.

On our next update(s):

  1. The new APK is saved as (1.apk) and (2.apk) is deleted (Repeat forever).

 

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:

adb shell "pm uninstall <full.packge.name>"
adb shell "rm -rf /data/app/<full.package.name>-*"

OR

Uninstall the app

Use your favorite method to delete BOTH:

/data/app/<full.package.name>-1.apk

/data/app/<full.package.name>-2.apk

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

Leave a Comment