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

Expo项目在Expo Go正常运行,打包APK后崩溃报‘main未注册’

Expo打包安卓APK后崩溃:"main"未注册问题

问题详情

使用Expo创建项目,npx expo start扫码在手机上运行正常,但执行eas build -p android --profile preview打包成APK安装后,安卓设备上应用直接崩溃,报错如下:

Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.

项目代码及配置

App.js

import React from 'react';
import {Text, View} from 'react-native';

const YourApp = () => {
  return (
    <View
      style={{
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
      }}>
      <Text>Try editing me! 🎉</Text>
    </View>
  );
};

export default YourApp;

app.json(存在语法错误)

{
  {
  "expo": {
    "name": "v5",
    "extra": {
      "eas": {
        "projectId": "4fc3529c-f92f-43aa-bc19-8f72f43e14a5"
      }
    }
  }
}

package.json

{
  "name": "push-notification",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "expo": "~49.0.13",
    "expo-status-bar": "~1.6.0",
    "firebase": "^10.4.0",
    "metro-core": "^0.79.1",
    "react": "18.2.0",
    "react-native": "0.72.5",
    "react-native-onesignal": "^5.0.1",
    "react-native-screens": "~3.22.0",
    "react-native-safe-area-context": "4.6.3"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0"
  },
  "private": true
}

解决方法

  • 修复app.json语法错误:最外层多了一对冗余大括号,修正后的正确结构:
    {
      "expo": {
        "name": "v5",
        "extra": {
          "eas": {
            "projectId": "4fc3529c-f92f-43aa-bc19-8f72f43e14a5"
          }
        }
      }
    }
    
  • 彻底清理缓存后重建:
    1. 执行 npx expo start --clear 清除本地Metro缓存
    2. 删除项目根目录下的.expo文件夹
    3. 重新运行 eas build -p android --profile preview
  • 排查第三方依赖冲突:临时移除react-native-onesignal依赖,重新打包测试。如果问题消失,说明该模块与当前Expo版本存在兼容问题,需查看其官方文档确认适配Expo 49的正确方式。
  • 确认入口文件配置:保持package.json中main字段的默认配置node_modules/expo/AppEntry.js,确保项目根目录下的App.js能被正确引用,不要随意修改入口相关的默认设置。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 12:58:15