Expo SDK52托管工作流Android构建失败:Gradle重复资源错误
Android Gradle构建失败:mergeReleaseResources重复资源错误
问题现象
执行命令 eas build --platform android --profile production 构建Android应用时,在Run gradlew阶段失败,核心报错如下:
BUILD FAILED in 3m 1s Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
进一步日志显示> Task :app:mergeReleaseResources FAILED,具体重复资源错误:
ERROR: [mipmap-hdpi-v4/ic_launcher] /home/expo/workingdir/build/{app}/android/app/src/main/res/mipmap-hdpi/ic_launcher.png [mipmap-hdpi-v4/ic_launcher] /home/expo/workingdir/build/{app}/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp: Resource and asset merger: Duplicate resources ERROR: [mipmap-xxhdpi-v4/ic_launcher] /home/expo/workingdir/build/{app}/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png [mipmap-xxhdpi-v4/ic_launcher] /home/expo/workingdir/build/{app}/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: Resource and asset merger: Duplicate resources ERROR: [mipmap-xhdpi-v4/ic_launcher] /home/expo/workingdir/build/{app}/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png [mipmap-xhdpi-v4/ic_launcher] /home/expo/workingdir/build/{app}/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp: Resource and asset merger: Duplicate resources ERROR: [mipmap-xxxhdpi-v4/ic_launcher] /home/expo/workingdir/build/{app}/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png [mipmap-xxxhdpi-v4/ic_launcher] /home/expo/workingdir/build/{app}/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: Resource and asset merger: Duplicate resources ERROR: [mipmap-mdpi-v4/ic_launcher] /home/expo/workingdir/build/{app}t/android/app/src/main/res/mipmap-mdpi/ic_launcher.png [mipmap-mdpi-v4/ic_launcher] /home/expo/workingdir/build/{app}/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp: Resource and asset merger: Duplicate resources
环境配置
- expo:
~52.0.38(托管工作流) - react-native:
0.76.7
app.json中已添加的expo-build-properties插件配置:
[ "expo-build-properties", { "android": { "compileSdkVersion": 35, "targetSdkVersion": 35, "buildToolsVersion": "35.0.0" } } ],
app.json的expo配置片段:
"expo": { "name": "{app}", "owner": "{owner}", "description": "{app}", "scheme": "{app}", "slug": "{app}", "platforms": ["ios", "android"], "version": "0.0.0", "orientation": "portrait", "icon": "./src/assets/icon.png", "android": { "package": "mono.", "versionCode": 30, "permissions": ["android.permission.CAMERA"], "icon": "./src/assets/icon.png" }, .... }
解决方案
1. 清理构建缓存
远程构建时,直接使用clean参数清理缓存后重新构建:
eas build --platform android --profile production --clean
本地开发可执行:
npx expo prebuild --clean
2. 指定资源生成格式
在app.json的android配置中,添加资源格式偏好,避免同时生成png和webp格式的图标:
"android": { // 保留原有配置 "icon": "./src/assets/icon.png", "resourceQualifiers": { "icon": { "formats": ["webp"] // 或选择["png"],二选一即可 } } }
如果使用自适应图标,优先配置adaptiveIcon字段,确保和icon配置无冲突:
"android": { // 保留原有配置 "adaptiveIcon": { "foregroundImage": "./src/assets/icon.png", "backgroundColor": "#ffffff" }, "resourceQualifiers": { "icon": { "formats": ["webp"] } } }
3. 排查第三方插件冲突
检查项目依赖的插件,确认是否有其他图标相关插件(如自定义图标插件、第三方UI库)额外生成了启动图标资源,导致重复。如有冲突,调整插件配置或移除冗余插件。
4. 手动清理重复资源(预构建场景)
如果上述方法无效,可预构建项目后手动清理重复资源:
- 执行预构建命令:
npx expo prebuild - 进入
android/app/src/main/res/目录,删除所有mipmap分辨率目录下的ic_launcher.png或ic_launcher.webp文件,仅保留一种格式。 - 将修改后的android目录提交到版本控制,再重新运行构建命令。
内容的提问来源于stack exchange,提问作者Shahryar Faraji
相关产品推荐
相关产品推荐

