You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行eas build构建Android APK时出现AAPT资源缺失错误

问题:EAS构建Android APK时Gradle资源错误

执行命令eas build -p android --profile preview --clear-cache生成APK时,在expo.dev上出现Gradle构建失败,错误信息如下:

Task :app:processReleaseResources 执行失败,Android资源链接出错,提示/home/expo/workingdir/build/android/app/src/main/res/drawable/splashscreen.xml:3中找不到资源color/splashscreen_background(即com.xxxxx.xxxxx:color/splashscreen_background)。

已尝试删除node_modules并重新执行npm install,问题未解决。


项目配置文件

app.json

{
  "expo": {
    "name": "Xxxxx",
    "slug": "Xxxxx",
    "owner": "xxxxx-xxxxx",
    "privacy": "public",
    "platforms": [
      "ios",
      "android"
    ],
    "version": "0.0.1",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "supportsTablet": true,
      "bundleIdentifier": "com.xxxxx.xxxxx",
      "buildNumber": "1.0.0",
      "splash": {
        "image": "./assets/splash.png",
        "resizeMode": "contain",
        "backgroundColor": "#ffffff"
      }
    },
    "android": {
      "package": "com.xxxxx.xxxxx",
      "versionCode": 1,
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#FFFFFF"
      },
      "splash": {
        "image": "./assets/splash.png",
        "resizeMode": "contain",
        "backgroundColor": "#ffffff"
      }
    },
    "web": {
      "favicon": "./assets/favicon.png"
    },
    "extra": {
      "eas": {
        "projectId": "e93c6d02-02d5-4238-8fe4-b03fdac9784b"
      }
    }
  }
}

package.json

{
  "name": "xxxxx",
  "version": "0.2.4",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "tunnel": "expo start --tunnel",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "test": "jest --verbose",
    "format": "prettier --write .",
    "storybook": "start-storybook -p 6006",
    "commit": "git add --all && git commit -m 'update' && git push",
    "storybook-generate": "sb-rn-get-stories --config-path .ondevice",
    "storybook-watch": "sb-rn-watcher --config-path .ondevice",
    "storybook:get": "sb-rn-get-stories --config-path .ondevice && STORYBOOK_ENABLED='true' expo start",
    "storybook:ios": "sb-rn-get-stories --config-path .ondevice && STORYBOOK_ENABLED='true' expo start --ios",
    "storybook:android": "sb-rn-get-stories --config-path .ondevice && STORYBOOK_ENABLED='true' expo start --android"
  },
  "dependencies": {
    "@babel/preset-env": "^7.24.5",
    "@react-native-async-storage/async-storage": "1.21.0",
    "@react-native-community/datetimepicker": "7.6.1",
    "@react-native-community/slider": "4.4.2",
    "@react-navigation/native": "^6.0.0",
    "@react-navigation/native-stack": "^6.0.0",
    "@types/jest": "^29.5.2",
    "axios": "^1.6.8",
    "expo": "~50.0.6",
    "expo-constants": "~15.4.6",
    "expo-status-bar": "~1.11.1",
    "jest": "^29.2.1",
    "jest-expo": "~50.0.4",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-native": "0.73.6",
    "react-native-safe-area-context": "4.8.2",
    "react-native-screens": "~3.29.0",
    "react-native-swiper": "^1.6.0",
    "react-native-web": "~0.19.6",
    "regenerator-runtime": "^0.14.1"
  },
  "devDependencies": {
    "@babel/core": "^7.24.5",
    "@babel/plugin-transform-runtime": "^7.24.3",
    "@storybook/addon-actions": "^6.5.16",
    "@storybook/addon-controls": "^6.5.16",
    "@storybook/addon-essentials": "^6.5.16",
    "@storybook/addon-links": "^6.5.16",
    "@storybook/addon-ondevice-actions": "^6.5.1",
    "@storybook/addon-ondevice-backgrounds": "^6.5.1",
    "@storybook/addon-ondevice-controls": "^6.5.1",
    "@storybook/addon-ondevice-notes": "^6.5.1",
    "@storybook/addon-react-native-web": "^0.0.19",
    "@storybook/builder-webpack5": "^6.5.14",
    "@storybook/manager-webpack5": "^6.5.14",
    "@storybook/react": "^6.5.16",
    "@storybook/react-native": "^6.5.7",
    "@testing-library/react-native": "^12.1.2",
    "@types/react": "~18.2.45",
    "atomic-bomb": "^5.0.0",
    "babel-loader": "^8.2.3",
    "babel-plugin-react-docgen-typescript": "^1.5.1",
    "babel-plugin-react-native-web": "^0.18.10",
    "metro-react-native-babel-preset": "^0.77.0",
    "typescript": "^5.3.0",
    "webpack": "^5.91.0"
  },
  "resolutions": {
    "react-native-svg": "13.4.0"
  },
  "private": true,
  "jest": {
    "preset": "jest-expo",
    "transformIgnorePatterns": [
      "node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)"
    ]
  },
  "babel": {
    "presets": [
      [
        "@babel/preset-env",
        {
          "loose": true,
          "shippedProposals": true
        }
      ]
    ]
  }
}

eas.json

{
  "cli": {
    "version": ">= 6.0.0"
  },
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal"
    },
    "preview": {
      "android": {
        "buildType": "apk"
      },
      "distribution": "internal"
    },
    "production": {}
  },
  "submit": {
    "production": {}
  }
}

metro.config.js

const { getDefaultConfig } = require('expo/metro-config')
const defaultConfig = getDefaultConfig(__dirname)
defaultConfig.resolver.resolverMainFields = [
'sbmodern',
...defaultConfig.resolver.resolverMainFields
]
defaultConfig.transformer.getTransformOptions = async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false
}
})
defaultConfig.watchFolders = [...defaultConfig.watchFolders, './.ondevice']
module.exports = defaultConfig

解决方案

针对splashscreen_background资源缺失的问题,可尝试以下步骤:

1. 手动添加缺失的颜色资源

在项目的android/app/src/main/res/values/colors.xml文件中(无则创建),添加对应颜色定义,值与app.json中splash.backgroundColor保持一致:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="splashscreen_background">#ffffff</color>
</resources>

2. 彻底清除缓存后重构

执行以下命令清除本地和EAS远程缓存:

expo r -c
eas build:clear-cache

再重新运行构建命令:

eas build -p android --profile preview --clear-cache

3. 同步Expo配置到本地项目

运行命令同步配置并清理本地Android目录(注意:会覆盖android目录,有自定义修改需先备份):

expo prebuild --clean

4. 排查Storybook配置冲突

临时注释metro.config.js中Storybook相关的watchFolders配置,重新构建验证是否解决问题:

// defaultConfig.watchFolders = [...defaultConfig.watchFolders, './.ondevice']

内容的提问来源于stack exchange,提问作者Erwin Nooteboom

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 15:05:53