AAPT:错误:<adaptive-icon>在 中<manifest>发现意外元素



我正在尝试在反应本机安卓中使用自适应图标,但它产品出现错误。

AAPT:错误:在 中发现意外元素

这是我的马尼菲斯.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下创建文件夹mipmap-anydpi-v26
  2. mipmap-anydpi-v26下创建ic_launcher_round.xml的文件
  3. 将下面的代码放在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相关代码,并记住自适应图标仅适用于 API 级别 26

查看官方文档以获取更多详细信息

最新更新