如果您在使用 Android Studio 时尝试安装此类应用,Logcat 将显示以下错误消息:
Installation did not succeed.
The application could not be installed: INSTALL_FAILED_VERIFICATION_FAILURE
List of apks:
[0] ‘…/build/outputs/apk/debug/app-debug.apk’
Installation failed due to: ‘null’
如果您的应用在需要声明 android:exported
的值时未进行此声明,则 Logcat 会提供以下错误消息:
Targeting S+ (version 10000 and above) requires that an explicit value for \
android:exported be defined when intent filters are present
以下代码段显示了一个服务示例,该服务包含 intent 过滤器并针对 Android 12 进行了正确配置:
<service android:name=“com.example.app.backgroundService”
android:exported=“false”>
如果以 Android 12 为目标平台,必须为应用创建的每个 PendingIntent 对象指定可变性。
要声明特定 PendingIntent 对象是否可变,请分别使用 PendingIntent.FLAG_MUTABLE
或 PendingIntent.FLAG_IMMUTABLE
标志。
如果您的应用创建未包含设置任何可变标志的 PendingIntent 对象,系统会抛出 IllegalArgumentException
,并在 Logcat 中显示以下消息:
PACKAGE_NAME: Targeting S+ (version 10000 and above) requires that one of \
FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if \
some functionalit