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

Expo项目APK真机启动失败:index.android.bundle错误求助

解决Expo Android APK真机启动"index.android.bundle"错误的方案

一、排查bundle打包完整性问题

  • 执行构建前清理缓存:运行npx expo prebuild --clean,再重新执行eas build,避免旧缓存导致bundle文件缺失或异常。
  • 优化eas.json构建配置,明确指定gradle构建命令,确保bundle被正确嵌入APK:
{
  "build": {
    "production": {
      "android": {
        "buildType": "apk",
        "gradleCommand": ":app:assembleRelease"
      },
      "ios": {}
    }
  }
}

二、针对通知权限模块isDevice判断的修正

  • 严格校验设备类型后再执行真机专属逻辑:模拟器下isDevice为false,真机为true,未做判断直接调用通知API会引发崩溃,示例修正代码:
import { Device } from 'react-native';
import * as Notifications from 'expo-notifications';

async function initNotifications() {
  if (Device.isDevice) {
    const { status } = await Notifications.getPermissionsAsync();
    if (status !== 'granted') {
      await Notifications.requestPermissionsAsync();
    }
    // 其他真机专属通知逻辑
  } else {
    // 模拟器下跳过权限请求或做兼容处理
  }
}
  • 延迟初始化通知逻辑:将依赖isDevice的代码放到useEffect中,避免APP启动初期设备信息未完成初始化就执行判断:
import { useEffect } from 'react';

function App() {
  useEffect(() => {
    initNotifications();
  }, []);
  
  // 其他组件内容
}

三、真机调试定位具体问题

  • 用adb查看错误日志:连接真机后运行adb logcat *:E,过滤出index.android.bundle相关的报错信息,定位具体代码行。
  • 构建开发版APK调试:在eas.json中添加开发版配置,打包后安装到真机,开启调试模式查看详细错误:
{
  "build": {
    "production": {
      "android": {
        "buildType": "apk",
        "gradleCommand": ":app:assembleRelease"
      },
      "ios": {}
    },
    "development": {
      "android": {
        "buildType": "apk",
        "developmentClient": true
      }
    }
  }
}

执行命令eas build --profile development --platform android完成打包,安装后通过调试菜单查看错误详情。

内容的提问来源于stack exchange,提问作者Uğurcan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 23:35:14