升级targetSDKVersion至31后Android 12安装报错求助
问题原因与解决方案
错误提示明确指向SomeAppLaunchActivity(即你代码中的AppLaunchActivity),问题出在这个带有IntentFilter的Activity没有显式声明android:exported属性——你仅在<application>标签中设置了该属性,但<application>的exported只是组件的默认值,无法覆盖Android 12+对带有IntentFilter组件的强制要求。
Android 12(API 31+)的规则是:所有包含IntentFilter的组件(Activity、Service、BroadcastReceiver)必须显式指定android:exported属性,无论<application>的默认配置是什么。
解决方法1:在Manifest中给目标Activity添加android:exported
在<application>标签内补充AppLaunchActivity的声明,明确设置android:exported(由于你的Activity带有Intent.ActionView过滤器,需要被外部应用唤起的话必须设为true):
<application android:label="Project" android:debuggable="false" android:theme="@style/OURTheme" android:icon="@drawable/our_icon_180px" android:requestLegacyExternalStorage="true" android:exported="false"> <!-- 已有的FileProvider配置 --> <provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data> </provider> <!-- 添加Activity声明并设置exported --> <activity android:name="crc6496621e99a539ca61.SomeAppLaunchActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> </intent-filter> </activity> </application>
解决方法2:通过Xamarin的ActivityAttribute设置(推荐)
在AppLaunchActivity.cs的Activity特性中直接添加Exported参数,无需手动修改Manifest,更符合Xamarin开发习惯:
[Activity(Exported = true)] [IntentFilter(new[] { Intent.ActionView }, AutoVerify = true, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable })] public class AppLaunchActivity : Activity { // 你的Activity逻辑代码 }
注意事项
- 如果该Activity是应用启动页(带有
LAUNCHER类型的IntentFilter),android:exported必须设为true,否则系统无法启动应用。 - 若Activity仅用于内部跳转、无需外部唤起,可设为
false,但结合你当前的Intent.ActionView过滤器,通常需要设为true以支持外部链接唤起。
内容的提问来源于stack exchange,提问作者angleUr
相关产品推荐
相关产品推荐

