使用EAS Build构建Android APK时Drawable后缀匹配错误求助
问题:EAS Build构建Android APK时因图片资源报错
执行命令eas build -p android --profile preview构建APK时,出现如下错误:
> Task :app:bundleReleaseJsAndAssets FAILED [stderr] error Don't know which android drawable suffix to use for asset: {"__packager_asset":true,"fileSystemLocation":"/home/expo/workingdir/build/assets/images/navigation/service","httpServerLocation":"/assets/assets/images/navigation/service","width":320,"height":130,"scales":[1,2,3,4,5],"files":["/home/expo/workingdir/build/assets/images/navigation/service/reservation_thum_img_1.png","/home/expo/workingdir/build/assets/images/navigation/service/reservation_thum_img_1@2x.png","/home/expo/workingdir/build/assets/images/navigation/service/reservation_thum_img_1@3x.png","/home/expo/workingdir/build/assets/images/navigation/service/reservation_thum_img_1@4x.png","/home/expo/workingdir/build/assets/images/navigation/service/reservation_thum_img_1@5x.png"],"hash":"b74c4d596b7a00b174f1cbbf6373edac","name":"reservation_thum_img_1","type":"png","fileHashes":["f8e111b8eadda7d33612a89b3337968d","08bbb315b8db585383bafaf3bbbb159f","b410e37fc8c275c98f2b07711193b9d2","5bc21bf4e96ae2a26d0f1f41a0bb9dc8","f9883a5447a863dde859d547da0c0fe7"]}. w: Detected multiple Kotlin daemon sessions at build/kotlin/sessions Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0. You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. See https://docs.gradle.org/7.3.3/userguide/command_line_interface.html#sec:command_line_warnings Execution optimizations have been disabled for 3 invalid unit(s) of work during this build to ensure correctness. Please consult deprecation warnings for more details. 933 actionable tasks: 933 executed [stderr] FAILURE: Build failed with an exception. [stderr] * What went wrong: [stderr] Execution failed for task ':app:bundleReleaseJsAndAssets'. [stderr] > Process 'command 'node'' finished with non-zero exit value 1 [stderr] * Try: [stderr] > Run with --stacktrace option to get the stack trace. [stderr] > Run with --info or --debug option to get more log output. [stderr] > Run with --scan to get full insights. [stderr] * Get more help at https://help.gradle.org [stderr] BUILD FAILED in 12m 49s Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.
项目配置文件
package.json
{ "name": "my-app", "version": "1.0.0", "main": "node_modules/expo/AppEntry.js", "scripts": { "start": "expo start", "android": "expo start --android", "ios": "expo start --ios", "eject": "expo eject", "test": "jest --watchAll" }, "jest": { "preset": "jest-expo" }, "resolutions": {}, "dependencies": { "@expo/react-native-action-sheet": "^4.0.1", "@expo/samples": "~3.0.3", "@expo/vector-icons": "^13.0.0", "@fortawesome/fontawesome-svg-core": "^6.2.1", "@fortawesome/free-solid-svg-icons": "^6.2.1", "@fortawesome/react-native-fontawesome": "^0.3.0", "@react-native-async-storage/async-storage": "^1.17.11", "@react-native-community/datetimepicker": "6.1.2", "axios": "^1.2.6", "crypto-js": "^4.1.1", "expo": "^45.0.0", "expo-app-loading": "~2.0.0", "expo-asset": "~8.5.0", "expo-blur": "~11.1.0", "expo-camera": "~12.2.0", "expo-cli": "^6.2.1", "expo-constants": "~13.1.1", "expo-file-system": "~14.0.0", "expo-font": "~10.1.0", "expo-image-manipulator": "~10.3.1", "expo-image-picker": "~13.1.1", "expo-linking": "~3.1.0", "expo-location": "~14.2.2", "expo-notifications": "~0.15.4", "expo-splash-screen": "^0.15.1", "expo-status-bar": "~1.3.0", "expo-updates": "~0.13.4", "expo-web-browser": "~10.2.1", "global": "^4.4.0", "immutable": "^4.2.2", "intl": "^1.2.5", "jwt-decode": "^3.1.2", "moment": "^2.29.4", "qs": "^6.11.0", "react": "17.0.2", "react-dom": "17.0.2", "react-geocode": "^0.2.3", "react-native": "0.68.2", "react-native-dash": "^0.0.11", "react-native-easy-toast": "^2.3.0", "react-native-elements": "^3.4.3", "react-native-gesture-handler": "~2.2.1", "react-native-image-resizer": "^1.0.1", "react-native-maps": "0.30.2", "react-native-measureme": "^0.0.2", "react-native-modal": "^13.0.1", "react-native-modal-datetime-picker": "^14.0.1", "react-native-picker-select": "^8.0.4", "react-native-push-notification-popup": "^1.6.1", "react-native-qrcode": "^0.2.7", "react-native-safe-area-context": "4.2.4", "react-native-screens": "~3.11.1", "react-native-status-bar-height": "^2.6.0", "react-native-svg": "12.3.0", "react-native-svg-transformer": "^1.0.0", "react-native-web": "0.17.7", "react-native-webview": "11.18.1", "react-navigation": "^3.11.0", "react-redux": "^8.0.5", "redux": "^4.2.1", "redux-actions": "^2.6.5", "redux-devtools-extension": "^2.13.8", "redux-pender": "^2.0.12", "underscore": "^1.13.6" }, "devDependencies": { "@babel/core": "^7.12.9" }, "private": true }
eas.json
{ "cli": { "version": ">= 3.5.2" }, "build": { "development": { "developmentClient": true, "distribution": "internal" }, "preview": { "distribution": "internal" }, "production": { "android": { "buildType": "apk" } } }, "submit": { "production": {} } }
原因分析
错误核心是Don't know which android drawable suffix to use for asset,本质原因:
- 你使用的Expo 45版本资源打包工具不支持
@4x、@5x这类高缩放比例的图片后缀,Android资源系统与Expo打包逻辑仅适配@1x、@2x、@3x版本,更高比例的图片无法匹配对应的drawable目录后缀,导致打包失败。 - 目标图片包含
@4x和@5x版本,超出了当前Expo版本的处理范围。
解决方案
方案1:移除多余的高缩放版本图片
直接删除reservation_thum_img_1@4x.png和reservation_thum_img_1@5x.png文件,保留@1x、@2x、@3x版本即可覆盖绝大多数Android设备的显示需求。
方案2:修改图片命名规则(需保留高分辨率图时)
将@4x和@5x的图片重命名为@3x后缀,或者合并为一张高分辨率的@3x版本图片,让Expo打包工具能正常识别处理。
方案3:升级Expo版本(可选)
如果项目允许,可尝试升级到Expo 48及以上版本,新版本的资源打包工具已支持更多缩放比例的图片,但升级前需确认所有依赖的兼容性,避免引入其他问题。
内容的提问来源于stack exchange,提问作者Kevin Yang
相关产品推荐
相关产品推荐

