失败[ INSTALL_FAILED_INVALID_APK ]

当我点击运行一个刚刚在 Android Studio 0.2.10中创建的项目,然后选择我的 Android (通过 USB 连接,通过 USB 调试) ,我得到了这个错误:

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]

知道是什么吗?

163861 次浏览

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

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

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

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

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.

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

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

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

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 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)

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

Force Stop the application in the device settings.

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

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.

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

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"

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

taskAffinity name must have at least one '.' separator

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)

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.

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.

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.

This helped in my case:

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

delete code in AndroidManifest.xml:

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

it works.

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.

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

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

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

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.

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.

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.

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.

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

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

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

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

try these commands:

cd android

then

./gradlew clean

then

react-native run-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

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.

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.

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.

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