Xamarin:当清单中的 TargetSdkVersion 设置为 API 31 时出现问题

Xamarin: Issue when TargetSdkVersion set to API 31 in manifest

参考Xamarin.Android 12.0 Release Notes,我将TargetFramework设置为Android 12,我可以毫无问题地部署项目。 但是,当我在 android 清单中将 android:targetSdkVersion 设置为 API 31 时遇到以下错误。

ADB0010: Mono.AndroidTools.InstallFailedException: Unexpected install output: Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/vmdl204773411.tmp/base.apk (at Binary XML file line #84): com.urbanairship.accengage.PackageUpdatedReceiver: Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present]

只有当 android:targetSdkVersion 设置为 31 并部署到物理 device/emulator 和 android 12 时才会发生这种情况。我已经将 android:exported="true" 添加到 MainActivity class 并且class使用 intent 过滤器的 es。谁能告诉我如何解决这个问题?

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="com.myapp.simulation" android:versionName="1.0.30" android:versionCode="110" xmlns:tools="http://schemas.android.com/tools">
  <uses-sdk android:minSdkVersion="24" android:targetSdkVersion="31" />
  <uses-permission android:name="android.permission.CALL_PHONE" />
  <uses-permission android:name="android.permission.CALL_PRIVILEGED" />
  <uses-permission android:name="android.permission.READ_CONTACTS" />
  <uses-permission android:name="android.permission.WRITE_CONTACTS" />
  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" />
  <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
  <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
  <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
  <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
  <uses-permission android:name="android.permission.USE_FINGERPRINT" />
  <uses-permission android:name="android.permission.USE_BIOMETRIC" />
  <uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.INTERNET" />

  <application tools:replace="android:allowBackup" android:name="android.support.multidex.MultiDexApplication" android:icon="@drawable/launcher_icon" android:allowBackup="false" android:fullBackupOnly="false" android:label="Sample App">
    <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
    <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:enabled="true" 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>
  </application>
</manifest>

根据错误消息,您项目中的 PackageUpdatedReceiver 没有为 android:exported 设置值。所以您可以尝试通过以下两种方式设置值。

  1. 在BroadCastReceiver的属性中设置:

[BroadcastReceiver(Exported = true)]

  1. 将其设置到 AndroidManifest.xml 中的 application 标签中:

编辑:对于android 12,所有服务,BroadCastReceivers,Activity 类 需要声明android:exported 的值。所以更新三部分sdk到最新版本