【问题标题】:Expo does not find "main" application in production build?世博会在生产构建中找不到“主要”应用程序?
【发布时间】:2019-12-24 02:41:31
【问题描述】:

几周前我一直在尝试修复此错误,但没有成功。问题是我无法发布我的应用程序。

当我为 iOS 或 Android 中的任何一个构建我的 expo 应用程序时,Expo CLI 签名过程运行良好,没有错误并生成最终包,但是当我将 spa 或 apk 文件安装到真实设备中时,它会显示启动屏幕连续 4 或 5 次(某种循环),最后显示以下错误消息:

签出没有结果:

https://forums.expo.io/t/application-main-has-not-been-registered/14395

Application main has not been registered

https://forums.expo.io/t/application-main-has-not-been-registered/11753

我的 package.json 看起来像这样:

{
  "name": "Sxunco",
  "homepage": "https://www.sxunco.com",
  "version": "1.0.3",
  "private": true,
  "main": "node_modules/expo/AppEntry.js",
  "jest": {
    "preset": "jest-expo",
    "transformIgnorePatterns": [
      "node_modules/(?!((jest-)?react-native|react-clone-referenced-element|expo(nent)?|@expo(nent)?/.*|react-navigation|redux-persist|native-base(-shoutem-theme)|native-base|react-native-router-flux))"
    ]
  },....

我的 App.js:

import React from 'react';
import Root from './src/native/index';
import configureStore from './src/store/index';

const { persistor, store } = configureStore();

export default function App() {
  return <Root store={store} persistor={persistor} />;
}

我尝试过同样的结果:

  • 在 app.json 中添加"appKey": "main"
  • AppRegistry.registerComponent(‘main’, () =&gt; App); 添加到 App.js 和 expo registerRootComponent(App) (分开和一起,都不起作用)
  • 更改“主”路径 package.json 直接到 App.js 并使用上述方法注册应用程序 手动

当我运行构建时,我也会运行:

exp start --no-dev --minify

所以我等待服务器完成加载然后运行expo build:android

我不知道该怎么做,因此我无法发布我的应用程序。

【问题讨论】:

  • 嗨@karlo 我也有同样的问题,你是怎么解决的?

标签: react-native build expo


【解决方案1】:

1) 检查 index.js 并确保 yourAppName 已注册,而不是 main:

app.json 根文件夹中的文件:

{
  "name": "TestSvgJoy",
  "displayName": "TestSvgJoy"
}

index.js(从根文件夹,如果你没有它,你需要更新 Xcode 中的构建脚本,如下所示)

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';

AppRegistry.registerComponent(appName, () => App);

这是应用在 Xcode 中的外观:

2) AppDelegate.m 应该有 2 行这样的

#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif

注意:如果您正在使用 Expo 并且应用未分离,则可以忽略此步骤。

3) 确保您的根文件夹包含 index.js 或 index.ios.js。

注意: 如果您需要 entryFileindex.jsindex.ios.js)的自定义路径,请转到 Xcode, project target, Build Phases, Bundle ReactNative code and images 并提供额外的参数,例如 ./src/index.ios.js

要快速测试并获取有关错误的更多信息,请转到 Xcode, Product, Scheme, Edit Scheme, Run, Build Configuration 并将其设置为 Release 并在模拟器上运行它。

【讨论】:

  • 您好弗洛林,感谢您的回答。我尝试将 "main":"App.js" 属性放在 package.json 上,并将 AppRegistry.registerComponent("Sxunco", () =&gt; App()); 放在 App.js 结尾,但没有,结果相同
  • 嗨,Karlo,我用更多细节更新了我的答案。仔细检查第 1 步并确保 index.js(或 index.ios.js)存在于根文件夹中。 (第 3 步)
【解决方案2】:

原来我的 App 是一个函数,而我只是将函数本身传递给两种注册方法(react native 和 expo):

registerRootComponent(App())

AppRegistry.registerComponent(appName, () =&gt; App());

但是在registerRootComponent 中我缺少一个箭头函数:S

registerRootComponent(()=&gt;App())

:)

【讨论】:

  • 我认为你不必使用 AppRegistry.registerComponent(appName, () => App());因为博览会本身通过 registerRootComponent 管理。
  • 我认为你不必使用 AppRegistry.registerComponent(appName, () => App());因为博览会本身通过 registerRootComponent 管理。
猜你喜欢
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 2020-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-05
  • 1970-01-01
相关资源
最近更新 更多