Karlo A. López
Karlo A. López

Reputation: 2668

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:

Checked out with no results:

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

My package.json looks like this:

{
  "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:

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:

When I run build I also run:

exp start --no-dev --minify

So I wait for the server to finish loading and then run expo build:android

Please I don't know what to do, I cannot publish my app because of this.

Upvotes: 2

Views: 4246

Answers (2)

Karlo A. L&#243;pez
Karlo A. L&#243;pez

Reputation: 2668

Turns out my App is a function, and I was just passing the function itself to both registration methods (react native & expo):

registerRootComponent(App())

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

But in registerRootComponent I was missing an arrow function :S

registerRootComponent(()=>App())

:)

Upvotes: 1

Florin Dobre
Florin Dobre

Reputation: 10252

1) check index.js and make sure yourAppName is registered, not main:

app.json file from root folder:

{
  "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)

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:

enter image description here

2) AppDelegate.m should have 2 lines like this

#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.

3) Make sure your root folder contains the index.js or 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 imagesand provide an extra parameter like ./src/index.ios.js

enter image description here 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.

enter image description here

Upvotes: 1

Related Questions