弹窗问题
升级安卓14后,应用没有适配对应的CPU架构而被系统强制弹窗,弹窗流程可见参考应用弹窗“此应用专为旧版Android打造,因此可能无法正常运行…”的原因,应用层面没办法去干扰这个流程,应该是在安装时有检测相关的包。
- 弹窗共有两个:此应用与最新版 Android 不兼容。请检查是否有更新,或与应用开发者联系。deprecated_abi_message
- 此应用专为旧版 Android 系统打造。它可能无法正常运行,也不包含最新的安全和隐私保护功能。请检查是否有更新,或与应用开发者联系。deprecated_target_sdk_message
从安卓源码中可以搜索到
问题1
在abiFilter申明arm64-v8a,此操作可能会导致异常,某些库并没有支持,需要更换。
android{ defaultConfig { ndk { abiFilters "armeabi", "armeabi-v7a", "x86", "arm64-v8a" } } }
在安卓源码中搜索deprecated_abi_message,可以找到一个DeprecatedAbiDialog,此类下有提交日志,显示是需要适配64位的
问题2
修改targetSdkVersion为28
在安卓源码中搜索deprecated_target_sdk_message,可以找到一个DeprecatedTargetSdkVersionDialog弹窗,它由AppWarnings.showDeprecatedTargetDialogIfNeeded拉起,判定是否拉起的关键是Build.VERSION.MIN_SUPPORTED_TARGET_SDK_INT,搜索这个变量,在frameworks/base/core/java/android/os/Build.java可以找到如下解释
/** * The current lowest supported value of app target SDK. Applications targeting * lower values may not function on devices running this SDK version. Its possible * values are defined in {@link Build.VERSION_CODES}. * * @hide */ public static final int MIN_SUPPORTED_TARGET_SDK_INT = SystemProperties.getInt( "ro.build.version.min_supported_target_sdk", 0);
搜索这个变量ro.build.version.min_supported_target_sdk,可以在build/make/tools/buildinfo.sh中找到脚本输出了PLATFORM_MIN_SUPPORTED_TARGET_SDK_VERSION的值,在build/make/core/version_util.mk中可以找到这个变量被设置为28。
为什么是28,回到frameworks/base/core/java/android/os/Build.java文件下,可以找到对应的版本说明,其中有提到前台服务的问题,而安卓14中对前台服务startForeground()有新的要求,可能是这个原因导致targetSdkVersion必须达到28
/** * P. * *Released publicly as Android 9 in August 2018. *
Applications targeting this or a later release will get these * new changes in behavior. For more information about this release, see the * Android 9 Pie overview.
*
-
*
- {@link android.app.Service#startForeground Service.startForeground} requires * that apps hold the permission * {@link android.Manifest.permission#FOREGROUND_SERVICE}. *
- {@link android.widget.LinearLayout} will always remeasure weighted children, * even if there is no excess space. *
安卓源码可以在Android Code Search上查看,以上源码于2023-10-25查阅
三连!!!