Expo构建阶段无法定位splash/icon等资源文件的问题求助
问题
Expo应用本地开发(Expo Go、Android模拟器运行)及npx expo-doctor检测均正常,但在Expo云端构建和Prebuild环节报错,提示无法找到./assets/splash.png、./assets/icon.png、./assets/adaptive-icon.png文件。
配置与日志信息
app.json相关配置片段
"splash": { "image": "./assets/splash.png", "resizeMode": "contain", "backgroundColor": "#0b0b0b" }, "android": { "adaptiveIcon": { "foregroundImage": "./assets/adaptive-icon.png", "backgroundColor": "#ffffff" } }, "expo": { "icon": "./assets/icon.png" },
Expo Build错误日志
[stderr] Error: Problem validating asset fields in app.json. [stderr] • Field: Android.adaptiveIcon.foregroundImage - cannot access file at './assets/adaptive-icon.png'. [stderr] • Field: Splash.image - cannot access file at './assets/splash.png'. [stderr] • Field: icon - cannot access file at './assets/icon.png'. [stderr] One or more checks failed, indicating possible issues with the project. Command "expo doctor" failed. npx -y expo-doctor exited with non-zero code: 1
本地npx expo-doctor检测结果
WARNING: We recommend using PowerShell or Bash via WSL 2 for development with Expo CLI on Windows. You may encounter issues using cmd.exe. ✔ Check Expo config for common issues ✔ Check package.json for common issues ✔ Check dependencies for packages that should not be installed directly ✔ Check for common project setup issues ✔ Check npm/ yarn versions ✔ Check Expo config (app.json/ app.config.js) schema ✔ Check for legacy global CLI installed locally ✔ Check that native modules do not use incompatible support packages ✔ Check that packages match versions required by installed Expo SDK ✔ Check that native modules use compatible support package versions for installed Expo SDK Didn't find any issues with the project!
Expo Prebuild错误日志
✖ Config sync failed [stderr] Error: [android.dangerous]: withAndroidDangerousBaseMod: ENOENT: no such file or directory, open './assets/adaptive-icon.png' [stderr] Error: [android.dangerous]: withAndroidDangerousBaseMod: ENOENT: no such file or directory, open './assets/adaptive-icon.png' [stderr] at Object.openSync (node:fs:590:3) [stderr] at readFileSync (node:fs:458:35) [stderr] at calculateHash (/home/expo/workingdir/build/node_modules/@expo/image-utils/build/Cache.js:14:91) [stderr] at createCacheKey (/home/expo/workingdir/build/node_modules/@expo/image-utils/build/Cache.js:19:18) [stderr] at Object.createCacheKeyWithDirectoryAsync (/home/expo/workingdir/build/node_modules/@expo/image-utils/build/Cache.js:24:33) [stderr] at generateImageAsync (/home/expo/workingdir/build/node_modules/@expo/image-utils/build/Image.js:151:34) [stderr] at async generateIconAsync (/home/expo/workingdir/build/node_modules/@expo/prebuild-config/build/plugins/icons/withAndroidIcons.js:350:11) [stderr] at async /home/expo/workingdir/build/node_modules/@expo/prebuild-config/build/plugins/icons/withAndroidIcons.js:278:21 [stderr] at async Promise.all (index 0) [stderr] at async generateMultiLayerImageAsync (/home/expo/workingdir/build/node_modules/@expo/prebuild-config/build/plugins/icons/withAndroidIcons.js:274:3) Error: Unknown error. See logs of the Prebuild build phase for more information.
解决方案
1. 检查.gitignore配置
云端构建依赖Git同步代码,确认.gitignore未误排除assets/目录或目标图片文件(比如是否存在assets/、*.png这类规则),避免构建服务器拉取不到文件。
2. 验证路径大小写
构建服务器多为Linux环境,区分文件名大小写,而本地Windows/macOS可能不区分:
- 检查本地文件实际命名是否和配置完全一致,比如是否存在
Splash.png而非splash.png - 确认
assets目录名为小写,避免Assets/和配置里的./assets/不匹配
3. 替换为根路径格式
将配置中的相对路径改为从项目根目录起始的绝对路径:
"splash": { "image": "/assets/splash.png" }, "android": { "adaptiveIcon": { "foregroundImage": "/assets/adaptive-icon.png" } }, "expo": { "icon": "/assets/icon.png" }
4. 清理缓存后重新同步
本地执行以下命令清理缓存,再重新提交代码到仓库:
npx expo prebuild --clean npx expo cache:clear
5. 确认文件层级
确保app.json位于项目根目录,assets目录与app.json同级;若使用app.config.js,确保配置路径是相对于项目根的。
6. 本地验证文件存在性
在终端执行命令,确认目标文件确实存在:
ls -la ./assets/
若文件缺失,重新添加正确的图片到assets目录。
内容的提问来源于stack exchange,提问作者Geret Wessling
相关产品推荐
相关产品推荐

