React 本机应用程序可与 expo go 配合使用,但在转换为 APK 时则无法使用

问题描述 投票:0回答:1

我正在尝试使用 expo 创建一个简单的项目。

这是我的代码

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;

当我运行

npx expo start
并通过扫描二维码在手机中运行程序时。但是当我使用
eas build -p android --profile preview
转译程序并安装该程序时,应用程序崩溃了(在我的 Android 手机和 Android 平板电脑中都是如此。

这是我的

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
}

这是错误:

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.

我搜索了有关该主题的先前主题,但没有找到有用的答案。从头开始该项目并没有帮助。

提前致谢!

我从头开始了一个项目,并尝试在 main 中调用应用程序注册表。

javascript firebase expo onesignal
1个回答
0
投票

我发现您的

main
中的
package.json
键设置为
node_modules/expo/AppEntry.js
。你的
registerRootComponent
住在哪里?

也许您可以尝试创建一个

index.js
文件,并将应用程序注册表行放入其中。它看起来像:

import { registerRootComponent } from 'expo';
import YourApp from './src/YourApp';

registerRootComponent(YourApp);

然后,尝试将

main
正在查看的路径更改为
index.js
所在的路径。

© www.soinside.com 2019 - 2024. All rights reserved.