Error: No resource found that matches the given name (at 'icon' with value '@mipmap/Icon')

本文介绍了一种解决在Android项目中遇到的图标资源未找到错误的方法。通过在assemblyinfo.cs文件中添加一行代码来指定应用图标的位置,可以有效解决此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题:

error: Error: No resource found that matches the given name (at 'icon' with value '@mipmap/Icon'). Phoneword E:\Phoneword\Phoneword\obj\Debug\android\manifest\AndroidManifest.xml

解决方法:

Here's a workaround. Go into assemblyinfo.cs (it's in the Properties folder in your project) and add the following line in there:

[assembly: Application(Icon = "@mipmap/icon")]

 

转载于:https://www.cnblogs.com/yechangzhong-826217795/p/8422254.html

### 配置 `mipmap` 资源作为应用图标的正确方法 在 Android 应用开发中,配置应用图标是一个常见的需求。通常情况下,开发者会在项目的 `AndroidManifest.xml` 文件中通过 `android:icon` 属性指定应用的启动图标。以下是关于如何正确配置 `mipmap` 资源作为应用图标的详细说明。 #### 1. 使用 `mipmap` 目录存储图标资源 `mipmap` 是专门为应用图标设计的一个特殊目录,它允许系统在不同分辨率设备上加载合适的图标版本[^1]。因此,推荐将应用图标存放在 `mipmap` 目录下而不是普通的 `drawable` 目录。这样可以确保即使其他图像被替换或删除,应用图标仍然可用。 #### 2. 修改 `AndroidManifest.xml` 中的应用图标路径 为了使应用能够识别并使用定义好的图标文件,需在 `AndroidManifest.xml` 的 `<application>` 标签中设置以下属性: ```xml <application ... android:icon="@mipmap/ic_launcher" ...> </application> ``` 上述代码片段中的 `@mipmap/ic_launcher` 表示从 `mipmap` 目录读取名为 `ic_launcher.png` 或者 `ic_launcher.webp` 的文件作为应用图标[^3]。 如果需要自定义更复杂的图标结构(例如带有前景和背景层),则可以通过矢量图形或者多层 PNG 图像实现,并分别命名为 `ic_launcher_foreground` 和 `ic_launcher_background`,最终组合成完整的图标。 #### 3. 处理高版本系统的适配问题 对于运行 Android 8.0 (API level 26) 及更高版本的设备,建议创建一个 XML 文件用于描述可适应性图标(adaptive icon),并将此文件放置于特定子目录如 `mipmap-anydpi-v26/` 下面。该 XML 文件的内容可能类似于下面的例子: ```xml <!-- res/mipmap-anydpi-v26/ic_launcher.xml --> <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> ``` 这种做法可以让新旧版安卓系统都获得最佳显示效果的同时保持兼容性。 #### 4. 解决常见错误——重复声明图标资源 当遇到类似 “Attribute application@icon value=(@drawable/ic_launcher)” 这样的编译期报错时,通常是由于在同一项目里存在多个地方指定了不同的默认图标所致。此时应该检查整个工程范围内是否有冲突性的设定;确认无误后再统一修改至目标位置即可消除此类警告信息。 --- ### 示例代码展示 假设我们需要更新现有应用程序以支持新的自定义图标方案,则按照前述指导完成操作后的部分关键文件改动如下所示: **Step A:** 更新 manifest 定义 ```xml <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp"> <application android:allowBackup="true" android:label="@string/app_name" android:theme="@style/AppTheme" android:icon="@mipmap/ic_launcher"> <!-- 设置为主 mipmap 图标 --> ... </application> </manifest> ``` **Step B:** 创建 adaptive icon xml 描述符 ```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="@mipmap/ic_launcher_foreground"/> </adaptive-icon> ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值