React-Native Android -不变性违规:“TheApp”尚未注册

djp7away  于 2023-06-24  发布在  React
关注(0)|答案(1)|浏览(214)

在我升级了我所有软件包的主要部分之后,当我运行react-native run-android时,我得到了这个错误:

Invariant Violation: "TheApp" has not been registered. This can happen if:
* Metro (the local dev server) is running from the wrong folder. Check if Metro is running, stop it, and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.

我在iOS上没有遇到这个问题,应用程序运行良好。
经过一些研究,我尝试了一些东西。React-Native 0.69用于两者。

MainApplication.java

我修改了这些行:

...
@Override
protected String getJSMainModuleName() {
  return "src/index.mobile"; //this line
}
...

MainActivity.java

我也修改了这些行:

...
@Override
protected String getMainComponentName() {
  return "TheApp"; //change the name here
}
...

在文件app.json中,我放了相同的名字:

{
  "name": "TheApp",
  "displayName": "TheApp"
}

最后,在移动的中,我这样做:

import './Business/Config/ReactotronConfig'
import { AppRegistry } from 'react-native'
import App from './mobile/App/Containers/App'

AppRegistry.registerComponent("TheApp", () => App)

一切都在iOS中运行,但在Android中不行。不知道该怎么办

k10s72fa

k10s72fa1#

我有一个类似的问题,这对我很有效。
我发现我的旧应用程序安装在我的android模拟器中。这为我修复了它:
1.我从模拟器卸载了应用程序和新应用程序。
1.我把地铁和模拟器都杀了
1.我重新启动了Metro和模拟器。
事实证明,模拟器保留了它安装的每个应用程序,而不是像我预期的那样每次都是一张白纸。当它启动时,它会尝试加载安装时间最早的应用程序。所以,它一直试图运行我的旧应用程序并联系旧的Metro服务器,而不是运行我的新应用程序。

相关问题