[英]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:我试过同样的结果:
"appKey": "main"
into app.json"appKey": "main"
到 app.jsonAppRegistry.registerComponent('main', () => App);
AppRegistry.registerComponent('main', () => App);
into App.js and also expo registerRootComponent(App)
(separated and both together, none of that works)registerRootComponent(App)
(分开并一起,都不起作用)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.js
或index.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.