Javascript React-Native:应用程序尚未注册错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38340360/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 21:21:24  来源:igfitidea点击:

React-Native: Application has not been registered error

javascriptfacebookreactjsreact-native

提问by Adam

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.

我目前正在阅读 React-Native 教程。我从入门教程开始,在那里我创建了一个新的 React Native 项目并成功地在我的设备上运行了该项目。

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:

然后我开始了Props 教程,我复制了代码片段并尝试再次运行该项目,并在我的屏幕上显示以下错误消息:

回答by Slowyn

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

react-native init AwesomeApp

But in your index.ios.js file you register other component

但是在您的 index.ios.js 文件中您注册了其他组件

AppRegistry.registerComponent('Bananas', () => Bananas);

AppRegistry.registerComponent('Bananas', () => Bananas);

When it mustbe

当它必须

AppRegistry.registerComponent('AwesomeApp', () => Bananas);

AppRegistry.registerComponent('AwesomeApp', () => Bananas);

Try to fix it.

尝试修复它。

回答by Afshin Mehrabani

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

大多数情况下,问题是您有另一个react-native start(即 React Native Packager)服务器在另一个终端或 TMUX 的另一个选项卡上运行(如果您使用的是 TMUX)。

You need to find that process and close it, so after running react-native run-iosfor instance, it will establish a new packager server that registered for that specific application.

您需要找到该进程并关闭它,react-native run-ios例如在运行后,它将建立一个新的打包服务器,为该特定应用程序注册。

Just find that process using:

只需使用以下方法找到该过程:

ps aux | grep react-native

find the process id (PID) and kill the packager process using killcommand (e.g. kill -9 [PID]). You should find the launchPackager.commandapp in macOS, not sure about the other operating systems.

找到进程 id (PID) 并使用kill命令 (例如kill -9 [PID])终止打包进程。您应该launchPackager.command在 macOS 中找到该应用程序,不确定其他操作系统。

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

然后尝试再次运行run-ios(或android)。运行新的打包服务器后,您应该能够看到新路径,例如:

Looking for JS files in
   /Users/afshin/Desktop/awesome-app 

回答by Daniyar Saumbayev

Modify MainActivitylike this,

修改MainActivity成这样,

@Override
protected String getMainComponentName() {
    return "Bananas"; // here
}

回答by user8637708

My solution is change module name in "AppDelegate.m"

我的解决方案是在“AppDelegate.m”中更改模块名称

from moduleName:@"AwesomeProject"

moduleName:@"AwesomeProject"

to moduleName:@"YourNewProjectName"

moduleName:@"YourNewProjectName"

回答by Rafael Ferraro

First of all you must start your application:

首先,您必须启动您的应用程序:

react-native start

Then, you must set your application name as the first argument of registerComponent.

然后,您必须将应用程序名称设置为 registerComponent 的第一个参数。

It works fine.

它工作正常。

AppRegistry.registerComponent('YourProjectName', () => YourComponentName);

回答by mperk

Please check your app.json file in project. if there has not line appKey then you must add it

请检查项目中的 app.json 文件。如果没有行 appKey 那么你必须添加它

{
  "expo": {
    "sdkVersion": "27.0.0",
    "appKey": "mydojo"
  },
  "name": "mydojo",
  "displayName": "mydojo"
}

回答by xemasiv

In my case there's this line in MainActivity.java which was missed when I used react-native-renamecli (from NPM)

就我而言,MainActivity.java 中有这一行,当我使用react-native-renamecli(来自 NPM)时被遗漏了

protected String getMainComponentName() {
    return "AwesomeApp";
}

Obviously ya gotta rename it to your app's name.

显然你必须将它重命名为你的应用程序的名称。

回答by Arshid KV

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

lsof -i :8081

Kill running node server :-

杀死正在运行的节点服务器:-

kill -9 <PID>

kill -9 <PID>

Eg:-

例如:-

kill -9 1653

kill -9 1653

Start node server from current react native folder:-

从当前反应本机文件夹启动节点服务器:-

react-native run-android

react-native run-android

回答by la5zl0

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.

我遇到了同样的问题,对我来说根本原因是我从另一个 react-native 文件夹(AwesomeApp)运行(react-native start)打包程序,而我在另一个文件夹中创建了另一个项目。

Running the packager from the new app's directory solved it.

从新应用程序的目录运行打包程序解决了它。

回答by linSir

you need to registerit in index.android.js / index.ios.js

你需要在 index.android.js / index.ios.js 中注册

like this:

像这样:

'use strict';

import {
    AppRegistry
} from 'react-native';

import app from "./app";

AppRegistry.registerComponent('test', () => app);