简体   繁体   English

Expo 在生产构建中找不到“主要”应用程序?

[英]Expo does not find "main" application in production build?

I've been trying to fix this error from a couple weeks ago with no success.几周前我一直在尝试修复这个错误,但没有成功。 The problem is I cannot publish my app because of this.问题是我因此无法发布我的应用程序。

When I build my expo app for any of both, iOS or Android, the Expo CLI signing process goes well, no errors and generates final bundles but when I install the spa or apk file into a real device it shows the splash screen 4 or 5 times in a row (some kind of loop) and finally shows the following error messages:当我为 iOS 或 Android 中的任何一个构建我的 expo 应用程序时,Expo CLI 签名过程进行得很顺利,没有错误并生成最终包,但是当我将 spa 或 apk 文件安装到真实设备中时,它会显示启动画面 4 或 5连续多次(某种循环),最后显示以下错误消息:

Checked out with no results:查了没有结果:

https://forums.expo.io/t/application-main-has-not-been-registered/14395 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 https://forums.expo.io/t/application-main-has-not-been-registered/11753

My package.json looks like this:我的 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))"
    ]
  },....

My App.js:我的 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} />;
}

Ive tried with same results:我试过同样的结果:

  • Adding "appKey": "main" into app.json"appKey": "main"到 app.json
  • Adding AppRegistry.registerComponent('main', () => App);添加AppRegistry.registerComponent('main', () => App); into App.js and also expo registerRootComponent(App) (separated and both together, none of that works)进入 App.js 和 expo registerRootComponent(App) (分开并一起,都不起作用)
  • Changing "main" path in package.json directly to App.js and register app with above methods manually将 package.json 中的“main”路径直接更改为 App.js 并使用上述方法手动注册应用程序

When I run build I also run:当我运行 build 我也运行:

exp start --no-dev --minify

So I wait for the server to finish loading and then run expo build:android所以我等待服务器完成加载然后运行expo build:android

Please I don't know what to do, I cannot publish my app because of this.请我不知道该怎么办,因此我无法发布我的应用程序。

1) check index.js and make sure yourAppName is registered, not main : 1)检查 index.js 并确保 yourAppName 已注册,而不是main

app.json file from root folder:根文件夹中的app.json文件:

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

index.js (from root folder, if you don't have it there you need to update build scripts in Xcode as below) index.js (来自根文件夹,如果你没有它,你需要在 Xcode 中更新构建脚本,如下所示)

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

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

This is how app would look in Xcode:这是应用程序在 Xcode 中的外观:

在此处输入图片说明

2) AppDelegate.m should have 2 lines like this 2) AppDelegate.m 应该有 2 行这样

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

Note: if you are using Expo and app was not detached you can ignore this step.注意:如果您使用的是 Expo 并且应用程序未分离,则可以忽略此步骤。

3) Make sure your root folder contains the index.js or index.ios.js. 3) 确保您的根文件夹包含 index.js 或 index.ios.js。

Note: If you need custom path of entryFile ( index.js or index.ios.js ) go to Xcode, project target, Build Phases, Bundle ReactNative code and images and provide an extra parameter like ./src/index.ios.js注意:如果您需要entryFile自定义路径( index.jsindex.ios.js ),请转到Xcode, project target, Build Phases, Bundle ReactNative code and images并提供一个额外的参数,如./src/index.ios.js

在此处输入图片说明 To test things quickly and get more info about the errors go to Xcode, Product, Scheme, Edit Scheme, Run, Build Configuration and set it to Release and run it on the simulator.要快速测试并获取有关错误的更多信息,请转到Xcode, Product, Scheme, Edit Scheme, Run, Build Configuration并将其设置为Release并在模拟器上运行。

在此处输入图片说明

Turns out my App is a function, and I was just passing the function itself to both registration methods (react native & expo):原来我的应用程序是一个函数,我只是将函数本身传递给两种注册方法(react native & expo):

registerRootComponent(App())

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

But in registerRootComponent I was missing an arrow function :S但是在registerRootComponent我缺少一个箭头函数:S

registerRootComponent(()=>App())

:) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM