[android] Failure [INSTALL_FAILED_INVALID_APK]

When I click to run a project I just created in Android Studio 0.2.10 and select my Android (connected by USB with debug by USB on) I get this error:

Waiting for device.
Target device: 0123456789ABCDEF
Uploading file
    local path: /Users/Rui/AndroidStudioProjects/FirstAppProject/FirstApp/build/apk/FirstApp-debug-unaligned.apk
    remote path: /data/local/tmp/rui.firstapp
Installing rui.firstapp
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/rui.firstapp"
pkg: /data/local/tmp/rui.firstapp
Failure [INSTALL_FAILED_INVALID_APK]

Any Idea of what it might be?

This question is related to android android-studio

The answer is


There seems to be multiple reasons for this failure. For me, the issue was that in AndroidManifest file I had referenced a non-existing library(only in this particular device) using the 'uses-library' tag. After removing the library which this device did not have the apk got installed properly.


I got this issue on a project with Dagger and multiple modules. What worked for me (none of the above worked) was to 1) empty the .gradle folder 2) empty the .idea folder 3) In project gradle.properties, mark org.gradle.caching=false 4) Possibly invalidate caches in AS, clean, rebuild

You may be able to get away with just #3, clean then build.

EDIT: Lately I've been able to get around this by restarting AS, then doing a clean, then install again.


If you have multiple modules project with multiple flavors and each flavor has a different applicationId then you have to make sure that all your modules are targeting the same build variant.
Active Build Variant from Android Studio


I had this issue and none of the above solutions worked for me.

The reason is probably root version phone that has available quota or apk install permissions only at the sdcard.

I fixed the issue using ADB (you'll need a rooted device):

  1. Connect your phone via USB
  2. Launch ADB using adb shell
  3. Switch to root mode using su
  4. create tmp folder in the sdcard: mkdir /sdcard/tmp
  5. cd /data/local
  6. create link the the folder in the sdcard: ln -s /sdcard/tmp tmp

I had this problem on android Studio because in my Debug build i've added version name suffix -DEBUG and the - was the problem.

Try to only have letters, numbers and dots on your version names and application ids


Don't know what exactly causes the issue.
A had several schemes, all could be build and install all of them and once, one didn't want (after what actions - don't know). In all unknown situations I execute:
npm run mac-reinstall
where in package.json in scripts section:
"mac-reinstall": "rm -rf -v package-lock.json ios/build ios/Podfile.lock android/.gradle android/build android/app/build node_modules && npm i && cd ios/ && rm -rf Pods/ && pod install && cd ../"
You can try to leave only Android's part from the script.


Navigate to Run/Debug Configurations

Click Run from the top Tab > Edit Configurations

  • Module: Select your App
  • Installation Options: Deploy Default APK
  • Ok

enter image description here


I just had same error. I had year 2015 in app id. I replaced 2015 by fifteen and that solved it.

Also, if you use Android Studio, you can try: Tools / Android / Synch Project with Gradle Files


It looks like having a number after the dot was the culprit.

I had the same issue with the following applicationId

org.tony.stark.125jarvis

Changing it to

org.tony.stark.jarvis

I was able to install the app to the android devices.


Uninstall the previous version if installed already and try again.It might help


Just remove old APK android/app/build/outputs/apk/debug/app-debug.apk in the folder. that's all. enjoy your coding...


If you write android:extractNativeLibs="false" in AndroidManifest file. then change it to android:extractNativeLibs="true"


After a great update, check that the applicationId of the build.gradle (Module: app) and the package in AndroidManifest.xml are identical. I had the same problem and so I solved it.


I found another reason of this error. If you rooted your device access permissions of /data/local/tmp may be changed, so adb can't get access to it temp file. Solution is to create "tmp" folder on sdcard and create symlink to it in /data/local/ (via ADB shell or Root Explorer).


i got similar issue once, what i observed was, package name in my Androidmanifest.xml was started with one empty space character. like " com.example.test" instead of "com.example.test"

I removed all such invalid spaces from my manifest file, it solved my problem

Edit 1: '-' in package name also cause same issue on some android versions


For Flutter projects, with VS Code editor, go to the project source folder and delete the "build" folder and start debugging.


I meet the similar issue, but it auto fixed after i reboot my Ubuntu PC,for I install some Ubuntu(12.04)app update,which leads to this issue.


I ran into this issue by having mismatched build variants. A Dynamic Delivery module was on the debug variant while the remaining modules were on release. Simply changing the Dynamic Delivery module to release, rebuilding, and installing, fixed the issue.


By turning off the Instant Run solved my issue. Don't know any explanation till now. After migrating to android studio 3.0 it starts problem like this. Hope this helps someone in future.


I had this issue and none of the above solutions worked for me.

For some reason, the permissions weren't set correctly on my /data/local/tmp directory (only root had rwx). I fixed the issue using ADB (you'll need a rooted device):

  1. Connect your phone via USB
  2. Launch ADB using adb shell
  3. Move to /data/local using cd /data/local
  4. Switch to root mode using su
  5. Allow read/write/execute on tmp directory using chmod 777 tmp
  6. Disconnect, restart Android Studio and plug in device again

I was facing this issue in android studio 3.4. By turning off the Instant Run solved my issue. Don't know any explanation till now. Hope this helps someone in future.


I had the same problem but none of the solutions worked for me. The problem was that I had no . separators in my package name.
i.e. if your package name is my.packagename its fine but it can't be just mypackagename
Got the hint from this bug report.

https://code.google.com/p/android/issues/detail?id=55841


If you have access to the device console (adb shell), then change permissions of following:

  1. chmod 777 /data/
  2. chmod 777 /data/local/
    You might also want to try copying the apk to /data/local/ in which case, make sure the set the right permissions to the apk also.
  3. chmod 777 /data/local/myapk.apk You can now attempt an installation by: pm install -r -d /data/local/myapk.apk (note the absolute path)

I was getting this in Android Studio and all I did to fix it was go to "Build" > "Clean Project" and it just worked.


The cause of this problem for me was having the wrong build variant selected for one of my app's modules. From the "Build Variants" tool, I selected the module variant which matched the app module, and it fixed the issue for me.


taskAffinity name must have at least one '.' separator


delete code in AndroidManifest.xml:

tools:replace="android:appComponentFactory" android:appComponentFactory=""

it works.


I have used the androidquickstart maven archetype and faced the same problem:

My package name was an only androidquickstart. According to advices before

  1. I have changed the package to androidquickstart.test
  2. then in AndroidManifest.xml I have changed package="androidquickstart" to package="androidquickstart.test" and correspondingly removed test from other parts of xml <activity android:name=".test.HelloAndroidActivity" > to <activity android:name=".HelloAndroidActivity" >
  3. and also fixed package issues in java files (highlighted by the IDE)

If someone is still having issue then Build->Clean Project then Build->Rebuild project finally Sync project with Gradle file.


I have recently had this problem building a multi-module, multi-apk application. As it turns out, my top level gradle build was modifying the android:versionCode, and that was making it out of sync with the manifests in the dynamic feature modules. This took me hours to find the cause, and only minutes to solve.

I found that the android studio log itself,

idea.log

, tells me way more about the problem than the IDE did.

2020-02-05 22:52:56,206 [thread 246]   WARN -            #com.android.ddmlib - Failed to commit install session 986623974 with command cmd package install-commit 986623974. Error: INSTALL_FAILED_INVALID_APK: /data/app/vmdl986623974.tmp/1_mytestapp-afat-debug version code 1829 inconsistent with 18290 
2020-02-05 22:52:56,206 [thread 246]   WARN - a.run.tasks.AbstractDeployTask - Install failed: The application could not be installed: INSTALL_FAILED_INVALID_APK The APKs are invalid. 

Force Stop the application in the device settings.


You can get this error if the minSdkVersion in builde.gradle is bigger than the device's Android version. In that case you have to modify the minSdkVersion.


I tried most above offered solutions (the simple ones, not those offering chmod and altering internal libraries) and none of them work

Eventually what worked for me was: "Clean Project" -> "Rebuild Project" -> changed the app versionName in the build.gradle app module -> Sync Gradle -> Run the app on the device


In my case, I get this error Failure [INSTALL_FAILED_INVALID_APK] when I try to install apk with pm install -r -d /sdcard/Download/foo.apk.

Since this package already uninstalled by pm uninstall <foo_package_name>, I try delete /data/local/tmp/<foo_package_name> but no luck.

I need reboot the android system to fixed. (Not sure remove data/local/tmp/<foo_package_name> step is necessary or not.)

[UPDATE]

It happen again just now, I try do not uninstall since I need to keep the apk inherit sdk 22 permission, so this time I use am force-stop <fook_package_name> to stop it first, then retry pm install, it fixed the error.


Your package name should include words combined by dots like com.example or prashant.mydairy..... it should work fine now

files where you must update ur package name are as below: 1)Manifest file 2)Gradle file(module appp): applicationId "package.name"


How to solve this issue:

  1. Install RootExplorer
  2. Create new tmp folder on SD card
  3. Long press on tmp folder, and select Link to this folder (last option in menu)
  4. Go to /data/local/ and tap button CREATE LINK from bottom

When I experienced this issue, what fixed it for me was making sure that the AndroidManifest.xml package name was the same as the build.grade applicationId.


This helped in my case:

Settings -> Apps -> Google Play Store -> Click "Enable" button.