AAPT: error: unexpected element <adaptive-icon> found in <manifest>

AAPT: error: unexpected element <adaptive-icon> found in <manifest>

我正在尝试在 React Native 中使用自适应图标 android 但它会出现以下错误。

AAPT: error: unexpected element found in

这是我的 manifes.xml

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.anar">

  <uses-permission android:name="android.permission.INTERNET" />   <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />   <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />   <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />   <uses-permission android:name="android.permission.VIBRATE" />



  <application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme">
    <activity android:screenOrientation="portrait" android:launchMode="singleTop" android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:windowSoftInputMode="adjustResize">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    <meta-data android:name="com.google.android.geo.API_KEY" android:value="MY_API_KEY_IS_HIDDEN"/>
    <service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
      <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
      </intent-filter>
    </service>

    <service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />

  </application>

  <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@color/ic_launcher_background" />
    <foreground android:drawable="@mipmap/ic_launcher_foreground" />   </adaptive-icon>



</manifest>

您已经使用 android:iconandroid:roundIcon 申请了 adaptive-icon。尝试从 AndroidManifest.xml

中删除那些额外的代码
<application
    android:icon="@mipmap/ic_launcher"
    android:roundIcon="@mipmap/ic_launcher_round"
    ...>

<!--<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@color/ic_launcher_background" />
    <foreground android:drawable="@mipmap/ic_launcher_foreground" />   
</adaptive-icon> -->

如果您查看 ic_launcher_round.xml,您会在那里看到那些代码,如果没有,请按照以下步骤创建一个:

  1. res
  2. 下创建文件夹 mipmap-anydpi-v26
  3. mipmap-anydpi-v26
  4. 下创建文件 ic_launcher_round.xml
  5. 将下面的代码放在 ic_launcher_round.xml
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@color/ic_launcher_background"/>
    <foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>

更新: 我已经检查了该网站提供的资源,它包含所有内容,只需从 AndroidManifest.xml 和 [= 中删除 adaptive-icon 相关代码33=]请记住,自适应图标仅适用于 API 级别 26

检查 official documentation 了解更多详情