React-Native: Application has not been registered error
I am currently going through the React-Native tutorials. I began with the Getting Started tutorial, where I made a new react native project and successfully managed to run the project on my device.
I then started the Props tutorial, I copied the code snippet and tried to run the project again and had the following error message show up on my screen:
I guess it is an error caused by not matching name of project and your registered component.
You have inited project with one name, i.e.
react-native init AwesomeApp
But in your index.ios.js file you register other component
AppRegistry.registerComponent('Bananas', () => Bananas);
When it must be
AppRegistry.registerComponent('AwesomeApp', () => Bananas);
Try to fix it.
Most of the times the problem is that you have another react-native start
(i.e. React Native Packager) server running either on another terminal or another tab of TMUX (if you are using TMUX).
You need to find that process and close it, so after running react-native run-ios
for instance, it will establish a new packager server that registered for that specific application.
Just find that process using:
ps aux | grep react-native
find the process id (PID) and kill the packager process using kill
command (e.g. kill -9 [PID]
). You should find the launchPackager.command
app in macOS, not sure about the other operating systems.
Then try to run the run-ios
(or android) again. You should be able to see the new path after running the new packager server, e.g.:
Looking for JS files in
/Users/afshin/Desktop/awesome-app
Modify MainActivity
like this,
@Override
protected String getMainComponentName() {
return "Bananas"; // here
}
First of all you must start your application:
react-native start
Then, you must set your application name as the first argument of registerComponent.
It works fine.
AppRegistry.registerComponent('YourProjectName', () => YourComponentName);
In my case there's this line in MainActivity.java which was missed when I used react-native-rename
cli (from NPM)
protected String getMainComponentName() {
return "AwesomeApp";
}
Obviously ya gotta rename it to your app's name.
I had the same problem and for me the root cause was that I ran (react-native start) the packager from another react-native folder (AwesomeApp), while I created another project in an other folder.
Running the packager from the new app's directory solved it.
My solution is change module name in "AppDelegate.m"
from
moduleName:@"AwesomeProject"
to
moduleName:@"NewName"
This can also be due to Root component name starts with lowercase.
Recorrect it or rather create the project once again with a PascalCase name.
e.g. ignite new HelloWord
you need to register it in index.android.js / index.ios.js
like this:
'use strict';
import {
AppRegistry
} from 'react-native';
import app from "./app";
AppRegistry.registerComponent('test', () => app);
The issue will also appear when, in index.js, you have named the app differently from the name you gave it for the android/ios package; probably this happened when you've ejected the app. So be sure that when calling AppRegistry.registerComponent('someappname', () => App)
, someappname is also used for the native packages or viceversa.
I think the node server is running from another folder. So kill it and run in the current folder.
Find running node server:-
lsof -i :8081
Kill running node server :-
kill -9 <PID>
Eg:-
kill -9 1653
Start node server from current react native folder:-
react-native run-android
Rather than changing the name in AppRegistry
,
Run react-native init Bananas , this will create react boilerplate code for Bananas project and AppRegistry.registerComponent
will automatically point to bananas
AppRegistry.registerComponent('Bananas', () => Bananas);
All the given answers did not work for me.
I had another node process running in another terminal, i closed that command terminal and everything worked as expected.
Non of the solutions worked for me. I had to kill the following process and re ran react-native run-android and it worked.
node ./local-cli/cli.js start
I had the same problem. I was using Windows for creating a react native app for android and was having the same error. Here's what worked.
- Navigate to the folder ANDROID in your root.
- Create a file with name : local.properties
- Open it in editor and write :
sdk.dir = C:\Users\ USERNAME \AppData\Local\Android\sdk
- Replace USERNAME with the name of your machine.
Save and run the app normally. That worked for me.
Please check your app.json file in project. if there has not line appKey then you must add it
{
"expo": {
"sdkVersion": "27.0.0",
"appKey": "mydojo"
},
"name": "mydojo",
"displayName": "mydojo"
}
Comments
Post a Comment