This happens when installing an update to an application, and the updated version cannot run with the same user ID as the previous version.
Why this happens
Android normally assigns user IDs on its own, and when an app is updated, it inherits the user ID of the previous version. There is one exception: Android allows multiple apps to run on the same user ID if they specify it in their manifest (by setting the android:sharedUserId
attribute in the <manifest>
element). If the new version requests a shared user ID but the previously installed one did not, the user ID will change and you will get an error. (Presumably also when trying to upgrade from a shared user ID to a version without.)
The error you get depends on the Android version: on Android 4.4.4 I have seen INSTALL_FAILED_UID_CHANGED
, whereas Android 10 reports INSTALL_FAILED_SHARED_USER_INCOMPATIBLE
.
You may also get this error if the app was uninstalled without removing its data (which can be done via adb shell
and pm uninstall -k
—if you know what you’re doing).
Two app data locations come into play here:
- App-private storage. This data is not normally accessible to end users; if you have root access, you can find the data in the file system ad
/data/data/packageID
.
- Private shared storage: this resides on your SD card at
/Android/data/packageID
.
How to recover
Recovering from this essentially means ensuring that there is no package (or leftover app data) with the same package name and an incompatible user ID. There are multiple ways to achieve this:
If you have root permission on your device, you can perform some surgery to preserve your app data across the update:
- Back up existing app data, delete the existing version, reinstall the new one and restore the data. Here’s how:
- Using oandbackup or similar, back up your app’s private data. (You don’t need to back up the APK but it doesn’t hurt.)
- If your app has a private shared storage directory (
/sdcard/Android/data/packageID
), open a shell on the device, enter su
to switch to root mode, and rename the directory (changing the package ID to a nonexistent one). This will also change file ownership for the directory from the app’s user to sdcard
.
- Uninstall the existing app.
- Install the new version.
- Restore the app’s private data (not the APK) using the same backup tool as above.
- If you have moved a private shared storage directory away, move it back to its old location (same steps as above). This will chage the file owner to the (new) user ID of the app.
If you do not have root permissions on your device, your options are somewhat more limited.
- Uninstall the existing app, then install the new version. You will lose the app’s private data. If your app has a private shared storage directory (
/sdcard/Android/data/packageID
), you can (probably) back it up before uninstalling and restore it after installing the new version. The more recent versions of Android support backing up private app data if the app allows it; you might be able to save your app data this way with a backup app, but I haven’t tried this.
- If you have uninstalled the old version already but kept the data, reinstall the old version, then proceed as above (uninstall and install new version).
- If you are just trying something out, you can give the new version a different package name. That will make Android (and app stores) treat it as a different app. The new version will not see the private data of the previous one, and if you deploy the app with the changed package name to an app store, it will appear as a different app rather than an upgrade to an existing one. This is definitely not recommended in production but may serve you in a lab setting.
- If nothing else works, perform a factory reset. This is even more destructive and will delete all your apps, along with their data.
/data/data/your.package.name
and/data/app
, seems like it was not fully uninstalled.