Failure [INSTALL_FAILED_INVALID_APK]
AndroidAndroid StudioAndroid Problem Overview
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?
Android Solutions
Solution 1 - Android
I was getting this in Android Studio and all I did to fix it was go to "Build" > "Clean Project"
and it just worked.
Solution 2 - Android
Just remove old APK android/app/build/outputs/apk/debug/app-debug.apk in the folder. that's all. enjoy your coding...
Solution 3 - Android
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
Solution 4 - Android
If someone is still having issue then Build->Clean Project then Build->Rebuild project finally Sync project with Gradle file.
Solution 5 - Android
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.
Solution 6 - Android
Navigate to Run/Debug Configurations
Click Run from the top Tab > Edit Configurations
- Module: Select your App
- Installation Options: Deploy Default APK
- Ok
Solution 7 - Android
How to solve this issue:
- Install
RootExplorer
- Create new
tmp
folder on SD card - Long press on tmp folder, and select
Link
to this folder (last option in menu) - Go to
/data/local/
and tap buttonCREATE LINK
from bottom
Solution 8 - Android
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):
- Connect your phone via USB
- Launch ADB using
adb shell
- Move to
/data/local
usingcd /data/local
- Switch to root mode using
su
- Allow read/write/execute on
tmp
directory usingchmod 777 tmp
- Disconnect, restart Android Studio and plug in device again
Solution 9 - Android
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.
Solution 10 - Android
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.
Solution 11 - Android
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
Solution 12 - Android
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).
Solution 13 - Android
If you write android:extractNativeLibs="false"
in AndroidManifest file. then change it to android:extractNativeLibs="true"
Solution 14 - Android
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.
Solution 15 - Android
For Flutter projects, with VS Code editor, go to the project source folder and delete the "build" folder and start debugging.
Solution 16 - Android
try these commands:
cd android
then
./gradlew clean
then
react-native run-android
Solution 17 - Android
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
Solution 18 - Android
This helped in my case:
Settings -> Apps -> Google Play Store -> Click "Enable" button.
Solution 19 - Android
I got this issue on a project with Dagger and multiple modules. What worked for me (none of the above worked) was to
- empty the .gradle folder
- empty the .idea folder
- In project gradle.properties, mark org.gradle.caching=false
- 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.
Solution 20 - Android
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.
Solution 21 - Android
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.
Solution 22 - Android
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.
Solution 23 - Android
Uninstall the previous version if installed already and try again.It might help
Solution 24 - Android
I have used the androidquickstart maven archetype and faced the same problem:
My package name was an only androidquickstart. According to advices before
- I have changed the package to androidquickstart.test
- then in AndroidManifest.xml I have changed
package="androidquickstart"
topackage="androidquickstart.test"
and correspondingly removed test from other parts of xml<activity android:name=".test.HelloAndroidActivity" >
to<activity android:name=".HelloAndroidActivity" >
- and also fixed package issues in java files (highlighted by the IDE)
Solution 25 - Android
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
Solution 26 - Android
Force Stop the application in the device settings.
Solution 27 - Android
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):
- Connect your phone via USB
- Launch ADB using adb shell
- Switch to root mode using su
- create tmp folder in the sdcard: mkdir /sdcard/tmp
- cd /data/local
- create link the the folder in the sdcard: ln -s /sdcard/tmp tmp
Solution 28 - Android
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.
Solution 29 - Android
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"
Solution 30 - Android
taskAffinity name must have at least one '.' separator
Solution 31 - Android
If you have access to the device console (adb shell), then change permissions of following:
- chmod 777 /data/
- 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. - 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)
Solution 32 - Android
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.
Solution 33 - Android
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
.
Solution 34 - Android
delete code in AndroidManifest.xml:
tools:replace="android:appComponentFactory" android:appComponentFactory=""
it works.
Solution 35 - Android
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.
Solution 36 - Android
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.
Solution 37 - Android
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.
Solution 38 - Android
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.
Solution 39 - Android
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.
Solution 40 - Android
if build clean doesn't work then check your build variants whether all the modules have the same variant.
Solution 41 - Android
I just faced the same problem with this message
> Error: ADB exited with exit code 1 Performing Streamed Install adb: > failed to install ~\build\app\outputs\flutter-apk\app.apk: Failure > [INSTALL_FAILED_INVALID_APK: Package couldn't be installed in > /data/app/com.example.weather_flutter-Azzrb6hHi67p7xfzCG6lyA==: > Package > /data/app/com.example.weather_flutter-Azzrb6hHi67p7xfzCG6lyA==/base.apk > code is missing] Error launching application on SM A105F.
And the solution worked for me was
deleting all file on this project directories build\app\outputs\apk\debug
and build\app\outputs\flutter-apk
and every thing went perfect from there
Solution 42 - Android
For those who might still be having this problem, You can cleaning, rebuilding and invalidating caches does not work, couple of things to try;
-
Upgrade Your gradle build version to the latest version.
-
If your code is kolin, check Kotlin version used for building with Gradle is same from the one bundled into the IDE plugin. Upgrade to that bundled into the IDE Then sync. I upgraded to android studio Arctic fox 2021, ha this issue, this worked for me.
Solution 43 - Android
For some reason when I updated my Android Studio to Artic Fox, this kept happening on my app flavours.
To be able to run the app again I needed to unnistall, clean and invalidate-crashes.
So I decided to update my version to Bumblebee, and now everything works without needing to invalidate-crashes, clean or unnistall my app.