RuiG
RuiG

Reputation: 1191

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?

Upvotes: 109

Views: 192959

Answers (30)

Anna Rafaela
Anna Rafaela

Reputation: 1

Navigate to

Run/Debug Configurations

Click Run from the top Tab > Edit Configurations

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

enter image description here

Upvotes: 0

Ali Khavari
Ali Khavari

Reputation: 1

I had this problem with a flutter app and I just deleted the "/android/app/build/outputs/apk/debug/app-debug.apk" file. I rerun it and it was fixed.

Upvotes: 0

Pedro Monteiro
Pedro Monteiro

Reputation: 47

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.

Upvotes: 0

DanIke
DanIke

Reputation: 91

For those who might still be having this problem, You can cleaning, rebuilding and invalidating caches does not work, couple of things to try;

  1. Upgrade Your gradle build version to the latest version.

  2. 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.

Upvotes: 0

Mutasim
Mutasim

Reputation: 36

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

Upvotes: 0

Rajkiran Kalowar
Rajkiran Kalowar

Reputation: 41

try these commands:

cd android 

then

./gradlew clean

then

react-native run-android

Upvotes: 4

Akshay
Akshay

Reputation: 71

if build clean doesn't work then check your build variants whether all the modules have the same variant.

Upvotes: 0

Ibrahim Disouki
Ibrahim Disouki

Reputation: 2693

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

Upvotes: 0

user14612787
user14612787

Reputation: 101

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

Upvotes: 10

Mahendren Mahisha
Mahendren Mahisha

Reputation: 1062

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

Upvotes: 44

Chaki_Black
Chaki_Black

Reputation: 932

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.

Upvotes: 0

Derek
Derek

Reputation: 11905

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. 

Upvotes: 1

Kirk
Kirk

Reputation: 193

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.

Upvotes: 2

Justin
Justin

Reputation: 2579

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.

Upvotes: 2

Abhi R
Abhi R

Reputation: 112

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

Upvotes: 3

clever_trevor
clever_trevor

Reputation: 1694

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.

Upvotes: 3

manish bansal
manish bansal

Reputation: 136

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.

Upvotes: 0

rigortek001
rigortek001

Reputation: 11

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.

Upvotes: 0

HMan
HMan

Reputation: 51

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

Upvotes: 5

Abctv Mobi
Abctv Mobi

Reputation: 11

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.

Upvotes: 1

林果皞
林果皞

Reputation: 7833

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.

Upvotes: 0

lichao
lichao

Reputation: 1

delete code in AndroidManifest.xml:

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

it works.

Upvotes: 0

sqr163
sqr163

Reputation: 1184

This helped in my case:

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

Upvotes: 2

anemomylos
anemomylos

Reputation: 641

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.

Upvotes: 0

Ismail Iqbal
Ismail Iqbal

Reputation: 2580

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.

Upvotes: 1

bluetoothfx
bluetoothfx

Reputation: 633

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.

Upvotes: 7

Sabin
Sabin

Reputation: 69

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)

Upvotes: 0

android_su
android_su

Reputation: 1687

taskAffinity name must have at least one '.' separator

Upvotes: 0

Sandeep PC
Sandeep PC

Reputation: 867

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

Upvotes: 14

Prashant Yalatwar
Prashant Yalatwar

Reputation: 179

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"

Upvotes: 0

Related Questions