【问题标题】:AAPT: error: unexpected element <adaptive-icon> found in <manifest>AAPT:错误:在 <manifest> 中发现了意外元素 <adaptive-icon>
【发布时间】:2020-02-04 10:07:39
【问题描述】:

我正在尝试在 react native android 中使用自适应图标,但它会产生以下错误。

AAPT:错误:在

中发现意外元素

这是我的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 react-native adaptive-icon


    【解决方案1】:

    您已经使用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

    查看official documentation了解更多详情

    【讨论】:

    • 我正在关注这个网络应用程序来生成图标,正如它所说我应该把它们都放在easyappicon.com/#infoModalAndroid
    • 如果我删除了这些部分,那么我实际上并没有使用自适应
    • 所以它已经有
    • 是的,将其从manifest中删除并手动检查文件mipmap-anydpi-v26/ic_launcher_round.xml
    猜你喜欢
    • 2022-01-20
    • 2022-01-24
    • 2019-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 2023-03-18
    • 1970-01-01
    相关资源
    最近更新 更多