上传AAB至Google Play遇android:exported属性未设置报错求助
android:exported属性 您上传的APK或Android App Bundle中存在带有intent filter的activity、activity alias、service或broadcast receiver,但未设置'android:exported'属性。
我的相关代码文件
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0.1" package="com.raitotec.faruj" android:installLocation="preferExternal" android:versionCode="1"> <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="31" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-feature android:name="android.hardware.location" android:required="false"/> <uses-feature android:name="android.hardware.location.gps" android:required="false" /> <uses-feature android:name="android.hardware.location.network" android:required="false" /> <application android:label="@string/app_name" android:icon="@drawable/logo" android:largeHeap="true"> <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" /> <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter > <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="${applicationId}" /> </intent-filter> </receiver> <uses-library android:name="org.apache.http.legacy" android:required="false" /> </application> </manifest>
启动页代码
[Activity(Label = "@string/app_name", Icon = "@drawable/Icon", Theme = "@style/splashscreen", MainLauncher = true, NoHistory = true, Exported = true)] public class SplashActivity : AppCompatActivity
主页面代码
[Activity(Label = "@string/app_name", Icon = "@drawable/Icon", Theme = "@style/MainTheme", MainLauncher = false, Exported = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
排查与解决办法
问题根源
Google Play对targetSdkVersion 31及以上的应用有强制要求:所有带有<intent-filter>的组件(Activity、Receiver、Service等)必须显式声明android:exported属性。你已经手动设置了自定义Activity的Exported属性,但问题来自第三方依赖库自动注入到Manifest中的组件——这些组件带有intent-filter但未设置android:exported。
解决步骤
查看合并后的完整Manifest
构建项目后,找到obj\Release\android\AndroidManifest.xml(Release模式),这个文件是合并了所有依赖库Manifest后的最终版本。搜索其中带有<intent-filter>但没有android:exported属性的组件,这些就是触发错误的源头。手动补全
android:exported属性
在你自己的AndroidManifest.xml的<application>标签内,添加对应组件的声明,显式设置android:exported:- 如果组件需要接收外部系统/应用的Intent(比如Firebase推送接收器),设置
android:exported="true" - 如果组件仅用于应用内部,设置
android:exported="false"
示例:
<!-- 假设发现FirebaseMessagingReceiver未设置exported --> <receiver android:name="com.google.firebase.messaging.FirebaseMessagingReceiver" android:exported="true"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> </intent-filter> </receiver>- 如果组件需要接收外部系统/应用的Intent(比如Firebase推送接收器),设置
更新第三方依赖库
绝大多数主流Xamarin库(如Xamarin.Firebase.Messaging)已经针对targetSdkVersion 31更新,会自动为组件添加android:exported属性。将所有依赖库更新到最新稳定版,可直接解决此类问题。检查其他插件组件
排查项目中使用的其他插件(如拍照、定位、DeepLink插件),确认它们注入的带有intent-filter的组件都已设置android:exported属性,必要时手动补充声明。
内容的提问来源于stack exchange,提问作者raito tec

