使用Expo CLI 6.0.5构建APK时出现AssertionError错误求助
Expo SDK 46构建APK报错:APK bundle must contain the expected embedded asset index.android.bundle
使用Expo CLI 6.0.5构建基于SDK 46的应用时,遇到以下错误:
java.lang.AssertionError: APK bundle must contain the expected embedded asset index.android.bundle
应用在本地开发模式运行正常,但从Google商店下载后直接崩溃,无法定位问题。
package.json 配置
{ "name": "dnd", "version": "1.0.0", "scripts": { "start": "expo start --dev-client", "android": "expo run:android", "ios": "expo run:ios", "web": "expo start --web", "eject": "expo eject" }, "dependencies": { "@fortawesome/fontawesome-svg-core": "^6.1.1", "@fortawesome/free-regular-svg-icons": "^6.1.1", "@fortawesome/free-solid-svg-icons": "^6.1.1", "@fortawesome/react-native-fontawesome": "^0.3.0", "@react-native-async-storage/async-storage": "~1.17.3", "@react-native-community/checkbox": "^0.5.12", "@react-navigation/native": "^6.0.11", "@react-navigation/native-stack": "^6.7.0", "@rneui/base": "^4.0.0-rc.5", "@rneui/themed": "^4.0.0-rc.5", "expo": "~46.0.8", "expo-checkbox": "~2.2.0", "expo-splash-screen": "~0.16.1", "expo-status-bar": "~1.4.0", "expo-updates": "~0.14.4", "react": "18.0.0", "react-dom": "18.0.0", "react-native": "0.69.4", "react-native-elements": "^3.4.2", "react-native-safe-area-context": "4.3.1", "react-native-screens": "~3.15.0", "react-native-svg": "12.3.0", "react-native-text-size": "^4.0.0-rc.1", "react-native-vector-icons": "^9.2.0", "react-native-web": "~18.7" }, "devDependencies": { "@babel/core": "^7.18.6", "@types/react": "~18.0.0", "@types/react-native": "~0.69.1", "typescript": "^4.6.3" }, "private": true }
app.json 配置
{ "expo": { "name": "Hoja de personaje 3.5e", "slug": "Hojadepersonaje35e", "version": "1.0.2", "owner": "calvix1", "orientation": "portrait", "icon": "./assets/appIcon.jpg", "userInterfaceStyle": "light", "splash": { "image": "./assets/splash.png", "resizeMode": "contain", "backgroundColor": "#ffffff" }, "updates": { "fallbackToCacheTimeout": 0 }, "assetBundlePatterns": [ "**/*" ], "ios": { "supportsTablet": true }, "android": { "package": "com.calvix1.hojadepersonaje35e", "softwareKeyboardLayoutMode":"pan", "adaptiveIcon": { "foregroundImage": "./assets/appIcon.jpg", "backgroundColor": "#FFFFFF" }, "versionCode":3 }, "web": { "favicon": "./assets/favicon.png" } } }
排查方案
调整expo-updates超时配置
当前fallbackToCacheTimeout设为0,会强制应用启动时立即检查更新,若网络不可用或更新未就绪,可能导致找不到本地bundle。尝试改为3000(3秒),给应用足够时间加载本地缓存:"updates": { "fallbackToCacheTimeout": 3000 }确认生产构建命令
确保构建生产包时使用expo build:android,而非expo run:android(后者是开发构建,依赖本地开发服务器,不会正确嵌入index.android.bundle)。清理构建缓存
执行以下命令清理缓存,避免旧资源干扰:expo r -c rm -rf node_modules npm install优化资源打包规则
当前assetBundlePatterns设为["**/*"],可能打包了不必要的文件。尝试缩小范围,仅包含必要资源目录:"assetBundlePatterns": [ "assets/**/*", "fonts/**/*" ]验证expo-updates包完整性
重新安装expo-updates确保没有损坏:npm uninstall expo-updates npm install expo-updates@~0.14.4检查APK内容
构建完成后解压APK,确认assets/index.android.bundle是否存在。若不存在,说明构建流程未正确嵌入bundle,需重新检查构建步骤。
内容的提问来源于stack exchange,提问作者santiago calvo
相关产品推荐
相关产品推荐

