为什么Android SDK 30会生成无效的APK文件? [英] Why does the Android SDK 30 generate invalid APK files?

查看:36
本文介绍了为什么Android SDK 30会生成无效的APK文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用全新安装的 Android Studio 4.1.2 在新 PC 上构建了一个新的 Java Android 应用程序,并且能够通过调试器在我的手机上正常运行它.但是,当我构建一个签名的 APK 文件(使用我的普通密钥存储文件)并将其复制到我的手机时,我无法像往常一样使用 Google Files 应用程序将它安装在手机上.几个小时后,我最终发现,如果我更改了 build.gradle 文件,使 compileSdkVersion、buildToolsVersion 和 targetSdkVersion 都是 29 而不是 30,那么 APK 安装正常.即使我的手机运行的是 Android 11 并且我的 build.gradle 中的 minSdkVersion 是 19 (Android 4.1).

I built a new Java Android app on a new PC using a fresh install of Android Studio 4.1.2, and was able to run it on my phone from the debugger fine. However, when I built a signed APK file (using my normal key store file) and copied it to my phone, I could not install it on the phone using the Google Files app, like I usually can. After several hours, I eventually worked out that if I changed my build.gradle file so that the compileSdkVersion, buildToolsVersion, and targetSdkVersion were all 29 instead of 30, then the APK installed fine. This is even though my phone is running Android 11 and the minSdkVersion in my build.gradle is 19 (Android 4.1).

该应用程序相当简单,由两个 Java 文件组成:一个主活动和一个扩展开源 NanoHTTPD 类的服务器类.NanoHTTPD jar 文件位于应用程序的 libs 文件夹中.该应用程序仅需要其清单中的以下权限:android.permission.INTERNET、android.permission.ACCESS_WIFI_STATE、android.permission.ACCESS_NETWORK_STATE

The app is fairly simple, consisting of two java files: a main activity and a server class which extends the open-source NanoHTTPD class. The NanoHTTPD jar file is in the app's libs folder. The app only requires the following permissions in it's manifest: android.permission.INTERNET, android.permission.ACCESS_WIFI_STATE, android.permission.ACCESS_NETWORK_STATE

我如何确定这是我做错了什么、是 Google SDK 30 版的错误还是 Android Studio 中的错误以便我可以将其报告给合适的人?谢谢.

How do I find out if this is something I'm doing wrong, a bug with version 30 of Google's SDK, or a bug in Android Studio so I can report it to the appropriate people? Thanks.

推荐答案

要找出您的 APK 未安装的原因,请使用命令行 adb 工具进行安装:

To find out why your APK is not installing, use command line adb tool to install it:

adb install myapp.apk

如果安装失败,adb会打印错误信息说明原因.

If the installation fails, adb will print an error message describing the reason.

无法从文件浏览器安装的一个可能原因是您的应用的调试版本仍安装在您的手机上.

One possible reason for failing to install from file browser is if the debug version of your app is still installed on your phone.

签名版本将具有相同的包名称但不同的签名,因此操作系统不会安装它.

The signed version would have the same package name but different signature, so the OS will not install it.

这篇关于为什么Android SDK 30会生成无效的APK文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆