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

查看:144
本文介绍了为什么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.

推荐答案

好的,现在解决.感谢Lev M关于使用adb尝试安装该应用程序的建议.那表明问题马上就解决了!

OK, solved now. Thanks to Lev M for the suggestion to use adb to try and install the app. That showed what the issue was straight away!

问题是,当我构建签名的APK文件时,我只勾选了"V1(Jar签名)".选项,但我还需要勾选"V2(完整APK签名)".看来您需要V2或更高版本才能对SDK 30进行签名.

The problem was that when I was building the signed APK file, I was only ticking the "V1 (Jar Signature)" option, but I also needed to tick "V2 (Full APK Signature)". It looks like you need V2 signing for SDK 30 onwards.

这已在此处确认: https://developer.android.com/about/versions/11/behavior-changes-11

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

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