当我升级了Android Studio 4和android gradle插件4.0.0之后,我遇到了一个奇怪的问题。我的APK无法部署到任何设备或模拟器上。让我解释一下我发现的与问题相关的内容。
1- 当我尝试通过单击Android Studio上的“运行”图标来运行应用程序时,构建成功完成。然后,什么也没有发生。
2- 当我尝试使用adb install部署已构建的APK时,它会显示以下错误。
1- 当我尝试通过单击Android Studio上的“运行”图标来运行应用程序时,构建成功完成。然后,什么也没有发生。
2- 当我尝试使用adb install部署已构建的APK时,它会显示以下错误。
adb: failed to install app/build/outputs/apk/debug/app-x86-debug.apk: Failure [INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION: Failed to parse /data/app/vmdl1686600827.tmp/base.apk: Corrupt XML binary file]
我还在另一个终端会话中检查了adb logcat
。我发现这个堆栈跟解析apk有关。我认为它对于找到解决方案会有帮助。
07-01 19:40:16.215 4454 7052 W ResourceType: Bad XML block: header size 28024 or total size 1702240364 is larger than data size 540
07-01 19:40:16.216 4454 7052 W PackageParser: Failed to parse /data/app/vmdl1686600827.tmp/base.apk
07-01 19:40:16.216 4454 7052 W PackageParser: java.io.FileNotFoundException: Corrupt XML binary file
07-01 19:40:16.216 4454 7052 W PackageParser: at android.content.res.ApkAssets.nativeOpenXml(Native Method)
07-01 19:40:16.216 4454 7052 W PackageParser: at android.content.res.ApkAssets.openXml(ApkAssets.java:152)
07-01 19:40:16.216 4454 7052 W PackageParser: at android.content.pm.PackageParser.parseApkLiteInner(PackageParser.java:1594)
07-01 19:40:16.216 4454 7052 W PackageParser: at android.content.pm.PackageParser.parseApkLite(PackageParser.java:1561)
07-01 19:40:16.216 4454 7052 W PackageParser: at com.android.server.pm.PackageInstallerSession.validateInstallLocked(PackageInstallerSession.java:1116)
07-01 19:40:16.216 4454 7052 W PackageParser: at com.android.server.pm.PackageInstallerSession.sealAndValidateLocked(PackageInstallerSession.java:865)
07-01 19:40:16.216 4454 7052 W PackageParser: at com.android.server.pm.PackageInstallerSession.commit(PackageInstallerSession.java:809)
07-01 19:40:16.216 4454 7052 W PackageParser: at android.content.pm.PackageInstaller$Session.commit(PackageInstaller.java:969)
07-01 19:40:16.216 4454 7052 W PackageParser: at com.android.server.pm.PackageManagerShellCommand.doCommitSession(PackageManagerShellCommand.java:2498)
07-01 19:40:16.216 4454 7052 W PackageParser: at com.android.server.pm.PackageManagerShellCommand.runInstall(PackageManagerShellCommand.java:919)
07-01 19:40:16.216 4454 7052 W PackageParser: at com.android.server.pm.PackageManagerShellCommand.onCommand(PackageManagerShellCommand.java:158)
07-01 19:40:16.216 4454 7052 W PackageParser: at android.os.ShellCommand.exec(ShellCommand.java:103)
07-01 19:40:16.216 4454 7052 W PackageParser: at com.android.server.pm.PackageManagerService.onShellCommand(PackageManagerService.java:21328)
07-01 19:40:16.216 4454 7052 W PackageParser: at android.os.Binder.shellCommand(Binder.java:634)
07-01 19:40:16.216 4454 7052 W PackageParser: at android.os.Binder.onTransact(Binder.java:532)
07-01 19:40:16.216 4454 7052 W PackageParser: at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:2821)
07-01 19:40:16.216 4454 7052 W PackageParser: at com.android.server.pm.PackageManagerService.onTransact(PackageManagerService.java:3856)
07-01 19:40:16.216 4454 7052 W PackageParser: at android.os.Binder.execTransact(Binder.java:731)
当我使用APK Analyzer分析构建的APK时,我发现versionName是未知的,合并的清单文件损坏且缺失。
我猜测在合并清单时出现了问题,但我无法理解确切的问题所在。你有任何想法吗?