当 Xamarin.Android 设置为 Android 12 时,我收到
“您上传了包含活动的 APK 或 Android 应用程序包,
具有意图过滤器的活动别名、服务或广播接收器,但是
没有设置“android:exported”属性。该文件不能
安装在 Android 12 或更高版本上。看:
developer.android.com/about/versions/12/behavior-changes-12#exported"
将 APK 上传到 Google Play 管理中心以发布新版本时出错。
我已将导出属性添加到我的活动和服务中,但仍然设置此错误。
[Activity(Label = "@string/AppDrawerName", Icon = "@mipmap/ic_launcher", RoundIcon = "@mipmap/ic_launcher_round", Theme = "@style/MainTheme", MainLauncher = true, Exported = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Portrait)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
Service
[Service(Exported = true)]
public class BarcodeService : IBarcodeService
{
从编译输出我可以看到下面的消息
命名空间“com.google.android.gms.stats”用于:AndroidManifest.xml,
AndroidManifest.xml。
android:exported 需要为元素显式指定
。应用定位
Android 12 及更高版本需要指定显式值android:exported
当相应的组件有意图时
过滤器定义。看https://developer.android.com/guide/topics/manifest/activity-element#exported https://developer.android.com/guide/topics/manifest/activity-element#exported了解详情。
然后我进入“obj/Debug”文件夹打开清单,我可以看到以下服务是自动生成的
<service android:name="crc640921eac73192168e.PNMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
有人知道我该如何设置[Service(Exported = true)]
对于这项服务,因为它是自动生成的?