首页 > 解决方案 > 必须声明清单元素

问题描述

此错误发生在位于 mipmap-anydpi-v26 目录中的 ic_launcher.xml 文件中,即使我尝试更改其位置也无法解决。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.robpercival.listviewdemo">

<application android:allowBackup="true"
             android:icon="@mipmap/ic_launcher"/>


</manifest >

RelativeLayout 和菜单元素也会出现类似的问题,我通过从可绘制目录中删除 ic_launcher 文件并在菜单和布局目录中创建新文件来解决这些问题。我不确定,但是当 android studio 版本更新到 3.5 时,可能会出现这些问题。

标签: androidmanifest

解决方案


问题是您从可绘制文件夹中删除“ic_launcher”文件以解决RelativeLayout 菜单元素问题,

但是这个文件链接在 mipmap 文件夹中/mipmap/ic_launcher/ic_launcher.xml/mipmap/ic_launcher_round/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="@drawable/ic_launcher_background" />
   <foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

只需删除2个文件

/mipmap/ic_launcher/ic_launcher.xml(anydpi-26)

/mipmap/ic_launcher_round/ic_launcher_round.xml(anydpi-26)

编辑

或者

将 ic_launcher_round(xxxhdpi) 复制到可绘制文件夹。

并编辑

/mipmap/ic_launcher/ic_launcher.xml(anydpi-26)

/mipmap/ic_launcher_round/ic_launcher_round.xml(anydpi-26)

像这样

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
  <background android:drawable="@drawable/ic_launcher_round" />
  <foreground android:drawable="@drawable/ic_launcher_round" />
</adaptive-icon>

推荐阅读