Xamarin.Android发布AAB至Google Play遇android:exported标志报错
解决Google Play发布时android:exported标志缺失问题
问题出在你项目自动生成的AndroidManifest.xml里的BroadcastMonitor接收器——它带有<intent-filter>但未显式声明android:exported属性。由于你的targetSdkVersion设为31(Android 12及以上),Google要求所有包含intent-filter的组件必须明确设置该属性。
你不需要修改MainActivity(自动生成的Manifest里已经给它加了android:exported="true",手动加会导致重复),只需在你编写的手动AndroidManifest.xml里补充这个接收器的配置即可,Xamarin构建时会自动合并两处配置:
修改后的手动AndroidManifest.xml内容:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="18" android:versionName="1.0" package="com.aa.bb" android:installLocation="auto"> <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" /> <application android:label="My App"> <!-- 补充BroadcastMonitor的android:exported属性 --> <receiver android:name="crc64a40206311a3a24ec.BroadcastMonitor" android:enabled="true" android:exported="true"> <intent-filter> <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" /> </intent-filter> </receiver> </application> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!--this is necessary for Android v6+ to get the device name and address--> </manifest>
说明
- 这里将
android:exported设为true,因为该接收器需要接收系统发送的蓝牙状态变化广播,外部(系统)需要能访问它。 - 构建时Xamarin会合并手动配置与自动生成的配置,给缺失属性的接收器补上声明,不会出现重复定义问题。
内容的提问来源于stack exchange,提问作者Robert Balaurea
相关产品推荐
相关产品推荐

