简体   繁体   English

如何修复 Android Studio 中的 INSTALL_FAILED_INVALID_APK 错误?

[英]How to fix INSTALL_FAILED_INVALID_APK error in Android Studio?

I have recently updated my Android Studio to 3.6.1, thereby also updating gradle plugin to 3.6.1 and the gradle wrapper to 5.6.4我最近将我的 Android Studio 更新为 3.6.1,从而也将 gradle 插件更新为 3.6.1,将 gradle 包装器更新为 5.6.4

When running the debug build, I keep getting this error运行调试版本时,我不断收到此错误

Install failed: The application could not be installed: 
INSTALL_FAILED_INVALID_APK 
The APKs are invalid. 
  • I have checked my package and applicationId and it is the same我检查了我的包和 applicationId,它是一样的
  • I tried using android:extractNativeLibs="true" on the manifest <application> tag and it is still does not work我尝试在清单<application>标签上使用android:extractNativeLibs="true"但它仍然不起作用
  • Kept on cleaning and rebuilding still doesn't work继续清理和重建仍然不起作用
  • Invalidated caches, deleted .gradle, idea, and build files and it still does not work无效的缓存,删除了 .gradle、idea 和构建文件,但它仍然不起作用
  • I have also used this on gradle.properties file org.gradle.caching=false but still does not work I checked the idea.log file and here is what it is saying:我也在 gradle.properties 文件org.gradle.caching=false上使用了它,但仍然不起作用我检查了idea.log文件,这是它的意思:
2020-03-22 00:49:04,191 [4654427]   INFO - ild.invoker.GradleBuildInvoker - Gradle build finished in 1 m 37 s 411 ms 
2020-03-22 00:49:04,213 [4654449]   INFO - ools.idea.run.tasks.DeployTask - Installing application: PACKAGE_NAME 
2020-03-22 00:49:04,451 [4654687]   INFO - a.run.tasks.AbstractDeployTask - 20675813ms TRC_BEG [12861][12861] : installer 
2020-03-22 00:49:04,451 [4654687]   INFO - a.run.tasks.AbstractDeployTask - 20675814ms TRC_BEG [12861][12861] : Command Dump 
2020-03-22 00:49:04,451 [4654687]   INFO - a.run.tasks.AbstractDeployTask - 20675814ms TRC_BEG [12861][12861] : get process ids 
2020-03-22 00:49:04,451 [4654687]   INFO - a.run.tasks.AbstractDeployTask - 20675872ms LOG_ERR [12861][12861] : Could not get package user id: /system/bin/run-as: unknown package: PACKAGE_NAME 

2020-03-22 00:49:04,451 [4654687]   INFO - a.run.tasks.AbstractDeployTask - 20675874ms TRC_END [12861][12861] :  
2020-03-22 00:49:04,451 [4654687]   INFO - a.run.tasks.AbstractDeployTask - 20675874ms TRC_BEG [12861][12861] : retrieve_apk_path 
2020-03-22 00:49:04,452 [4654688]   INFO - a.run.tasks.AbstractDeployTask - 20675874ms TRC_BEG [12861][12861] : apk_path_via_cmd_package_dump 
2020-03-22 00:49:04,452 [4654688]   INFO - a.run.tasks.AbstractDeployTask - 20675923ms TRC_END [12861][12861] :  
2020-03-22 00:49:04,452 [4654688]   INFO - a.run.tasks.AbstractDeployTask - 20675923ms TRC_END [12861][12861] :  
2020-03-22 00:49:04,452 [4654688]   INFO - a.run.tasks.AbstractDeployTask - 20675923ms LOG_ERR [12861][12861] : Could not find apks for package: PACKAGE_NAME 
2020-03-22 00:49:04,452 [4654688]   INFO - a.run.tasks.AbstractDeployTask - 20675923ms TRC_END [12861][12861] :  
2020-03-22 00:49:04,452 [4654688]   INFO - a.run.tasks.AbstractDeployTask - 20675923ms TRC_END [12861][12861] :  
2020-03-22 00:49:04,452 [4654688]   INFO - a.run.tasks.AbstractDeployTask - DUMP_UNKNOWN_PACKAGE 
2020-03-22 00:49:04,967 [4655203]   INFO -            #com.android.ddmlib - Created install session 969164047 with options -r -t -S 14667707 
2020-03-22 00:49:04,967 [4655203]   INFO -            #com.android.ddmlib - Uploading APK C:\Projects\PROJECT_FOLDER\source\PROJECT_NAME\app\build\outputs\apk\debug\app-debug.apk to session 969164047 
2020-03-22 00:49:08,055 [4658291]   INFO - WindowsPerformanceHintsChecker - Windows Defender status: NONE_EXCLUDED; projectDirExcluded? false 
2020-03-22 00:49:17,686 [4667922]   WARN -            #com.android.ddmlib - Failed to commit install session 969164047 with command cmd package install-commit 969164047. Error: INSTALL_FAILED_INVALID_APK: Package couldn't be installed in /data/app/PACKAGE_NAME -d9UfJVvKMP9-OA81TwCVvQ==: Package /data/app/PACKAGE_NAME -d9UfJVvKMP9-OA81TwCVvQ==/base.apk code is missing 
2020-03-22 00:49:17,687 [4667923]   WARN - a.run.tasks.AbstractDeployTask - Install failed: The application could not be installed: INSTALL_FAILED_INVALID_APK The APKs are invalid. 
2020-03-22 00:49:17,689 [4667925]   INFO - run.AndroidLogcatOutputCapture - stopAll() 
2020-03-22 00:49:21,408 [4671644]   INFO - rationStore.ComponentStoreImpl - Saving appEditorColorsManagerImpl took 12 ms 

*Take note I replaced my package name with PACKAGE_NAME and project names *注意我用 PACKAGE_NAME 和项目名称替换了我的包名称

I have run out of options.我已经没有选择了。 Worst case is I will downgrade gradle and gradle wraper and even Android Studio, which I deliberately hate as it is a step backwards最坏的情况是我会降级 gradle 和 gradle wrapper 甚至 Android Studio,我故意讨厌它,因为它是一种倒退

另一种解决方案是删除 ../android/app/build/outputs/apk/debug/app-debug.apk 文件,然后运行“npm run android”/“yarn android”

I tried updating the Android Studio but it still get the INSTALL_FAILED_INVALID_APK error.我尝试更新 Android Studio,但它仍然收到 INSTALL_FAILED_INVALID_APK 错误。 Then I updated the firebase dependencies and still to no avail然后我更新了 firebase 依赖项,但仍然无济于事

Interestingly though, it worked smoothly on another project that I have.有趣的是,它在我的另一个项目上运行得很顺利。 Which led me to check which dependencies they differ in and realized that the only major dependency is the AppDynamics gradle plugin这让我检查了它们不同的依赖项,并意识到唯一的主要依赖项是 AppDynamics gradle 插件

I remove the AppDynamics instrumentation and it worked!我删除了 AppDynamics 工具并且它起作用了! I am assuming that even before, the AppDynamics instrumentation in gradle was the cause that prevented the app from running properly.我假设甚至在此之前,gradle 中的 AppDynamics 检测是阻止应用程序正常运行的原因。 I have confirmed it is an issue with the AppDynamics plugin.我已经确认这是 AppDynamics 插件的问题。 See link for reference: https://community.appdynamics.com/t5/End-User-Monitoring-EUM/AppDynamic-EUM-setup-for-Android-Cordova-project/td-p/38864请参阅链接以供参考: https : //community.appdynamics.com/t5/End-User-Monitoring-EUM/AppDynamic-EUM-setup-for-Android-Cordova-project/td-p/38864

For the meantime, I will be downgrading until AppDynamics provides a fix与此同时,我将降级,直到 AppDynamics 提供修复

Sometimes it is because of the emulator/device you are installing your apk on.有时是因为您安装apk的模拟器/设备。 If you have previously installed apk on a device and then uninstalled, then it might still exist on your device.如果您之前在设备上安装了apk然后又卸载了,那么它可能仍然存在于您的设备上。 So, in the emulator, go to settings -> Apps , then check for the application in the list.因此,在模拟器中,转到settings -> Apps ,然后检查列表中的应用程序。 If exist, click on that particular application and then click on 'Uninstall for all users'(Typically from three dots in right corner).如果存在,请单击该特定应用程序,然后单击“为所有用户卸载”(通常从右上角的三个点)。

Hope it helps :)希望能帮助到你 :)

使用相同的捆绑 ID 删除手机上的现有应用程序对我有用。

I remember having the same issue and solving it with build>clean project.我记得有同样的问题并用 build>clean 项目解决它。 but as you say that this doesnt work here is a link talking about subtle changes in your apps package name in the Manifest and its pretty recent.但正如您所说,这在这里不起作用是一个链接,该链接讨论了清单中应用程序包名称的细微变化及其最近的变化。 Just thought it might be woth a look as it does not appear in the list of things you have already checked.只是认为它可能值得一看,因为它没有出现在您已经检查过的事物列表中。 plus the logs you published talk about the package name being unknown so that seems suspicious.加上您发布的日志谈论包名称未知,因此看起来很可疑。

I hope it helps我希望它有帮助

When you are set up the emulator (AVD) you are choosing the External & Internal storage sizes.设置模拟器 (AVD) 时,您将选择外部和内部存储大小。

在此处输入图片说明

AND I think you exceeded that storage size.而且我认为您超出了该存储大小。

Solutions (They are all under freeing some storage "category"):-解决方案(他们都在释放一些存储“类别”):-

  • Uninstall unnecessary apps.卸载不必要的应用程序。
  • Wipe emulator data from AVD manager.从 AVD 管理器中擦除模拟器数据。
  • Extend the storage size by editing the specific emulator.通过编辑特定的模拟器来扩展存储大小。

I faced the same issue.我遇到了同样的问题。 Try to uninstall the app via terminal adb uninstall com.packagename command and then reinstall the app.尝试通过终端adb uninstall com.packagename命令卸载应用程序,然后重新安装应用程序。 Basically, sometimes the app is isntalled for other users in device and uninstalling from device just uninstalls it from current user, that's why it gives this error.基本上,有时该应用程序是为设备中的其他用户安装的,而从设备上卸载只会从当前用户那里卸载它,这就是它出现此错误的原因。 Give it a try, I hope it will helps.试一试,我希望它会有所帮助。

The problem started happening for me in Android Studio 4.0.这个问题在我的 Android Studio 4.0 中开始发生。 I get "INSTALL_FAILED_INVALID_APK" when trying to launch an app on Emulator right after opening Android Studio.在打开 Android Studio 后立即尝试在模拟器上启动应用程序时,我收到“INSTALL_FAILED_INVALID_APK”。

Found a workaround - if I launch the app on real device first, then launching on emulator is not a problem.找到了一个解决方法 - 如果我先在真实设备上启动应用程序,那么在模拟器上启动就不是问题。 Works 100%.工作 100%。

Android Studio is still buggy as hell, unfortunately...不幸的是,Android Studio 仍然有很多问题……

What works for me is to do the following:对我有用的是执行以下操作:

  1. Uninstall the dev version (or store version of the app).卸载开发版(或应用商店版)。 If you have an app with the same bundle id it will refuse to install a different variation of the sample app.如果您的应用程序具有相同的 bundle id,它将拒绝安装示例应用程序的不同变体。 adb uninstall <BUNDLE_ID>
  2. refresh the android build cd ./android && ./gradlew clean && cd ../刷新android build cd ./android && ./gradlew clean && cd ../
  3. Run react-native run-android --variant=release运行react-native run-android --variant=release
application>- android:extractNativeLibs="true" 

work for me为我工作


minSdkVersion 23

ndk {
   abiFilters "armeabi-v7a"
}

minSdkVersion is less than 23, work for me too minSdkVersion 小于 23,对我也有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM