当前位置:   article > 正文

常见React本机错误

make sure you have the android development environment set up:

Recently I try to dirty my hands with react native. As I come from a React background, It’s easy to understand the concepts because of the same coding language. Here comes the tough part. Run the app, create the app, and many more things are there that make you angry. so let’s narrow it down. So I find the perfect working solutions for some common react-native errors.

最近,我试图用原生的方法弄脏我的手。 正如我来自React的背景一样,由于使用了相同的编码语言,因此很容易理解这些概念。 困难的部分到了。 运行该应用程序,创建该应用程序,还有更多让您生气的事情。 所以我们缩小范围。 因此,对于某些常见的本机错误,我找到了理想的工作解决方案。

模拟器停留在“从localhost:8081加载”上。 (Emulator stuck on “loading from localhost:8081..”)

There could be several cases where you can’t connect to the debugger:

在某些情况下,您无法连接到调试器:

The device and host machine definitely should be on the same network. Either connect your mobile to your PC’s network or your pc to the mobile hotspot. In some cases on real devices, you might need to run adbe reverse command:

设备和主机绝对应该在同一网络上。 将您的移动设备连接到PC的网络,或者将PC连接到移动热点。 在某些情况下,在实际设备上,您可能需要运行adbe reverse命令:

adb reverse tcp:8081 tcp:8081

Uninstall the app, stop the packager, and restart the packager with reset cache option:

卸载应用程序,停止打包程序,然后使用“重置缓存”选项重新启动打包程序:

npm start -- --reset-cache

And then, run it on the device again. Shake your device and in the menu choose dev settings. In the debug server host & port for device section enter your pc IP address via port 8081 like this: 192.168.1.3:8081.

然后,再次在设备上运行它。 摇动设备,然后在菜单中选择开发者设置。 在设备的调试服务器主机和端口部分中,通过端口8081输入您的PC IP地址,如下所示: 192.168.1.3:8081 :8081。

无法安装该应用程序。 确保您拥有Android开发环境 (Failed to install the app. Make sure you have the Android development environment)

解决方案1:(Solution 1:)

I was receiving this error message when running react-native run-android. When I ran cd android && ./gradlew clean I was getting permission errors also. I ran chmod +x gradlew and it started working.

运行react-native run-android时,我收到此错误消息。 当我运行cd android && ./gradlew clean我也收到权限错误。 我运行chmod +x gradlew ,它开始工作。

解决方案2 (Solution 2)

To make sure your environment is set up properly for android, go to the root of your react-native project. Open the android project(folder) in the Android Studio IDE.

为了确保您的环境已针对android正确设置,请转到您的react-native项目的根目录。 在Android Studio IDE中打开android项目(文件夹)。

All errors with your environment will show up, and that will automatically start the Gradle Daemon to sync and configure the build for you. Once it finished, close the Android Studio and come back to command-line and run: react-native run-android

您环境中的所有错误都会显示出来,并且会自动启动Gradle Daemon来为您同步和配置构建。 完成后,关闭Android Studio,然后返回命令行并运行: react-native run-android

“运行Android”卡在JS Metro Bundler上 (“run-android” stuck on JS Metro Bundler)

I have got the solution for the problem

我有解决问题的方法

  1. go to your project and run 2 command shell

    转到您的项目并运行2命令外壳
  2. in the first shell, run npm start

    在第一个shell中,运行npm start

  3. in the second shell, react-native run-android

    在第二个shell中, react-native run-android

    then it will run

    然后它将运行

react-native:找不到命令(react-native: command not found)

After adding the right path to the PATH variable issue is resolved. Below are the steps to find the right path.

将正确的路径添加到PATH变量后,问题得以解决。 以下是找到正确路径的步骤。

1. Enter: npm install -g react-native-clioutput: /usr/local/Cellar/node/6.1.0/libexec/npm/bin/react-native ->/usr/local/Cellar/node/6.1.0/libexec/npm/lib/node_modules/react-native-cli/index.js/usr/local/Cellar/node/6.1.0/libexec/npm/lib└── react-native-cli@0.2.0

from above output you can clearly see the path: /usr/local/Cellar/node/6.1.0/libexec/npm/bin/react-native

从上面的输出中,您可以清楚地看到路径: /usr/local/Cellar/node/6.1.0/libexec/npm/bin/react-native

export PATH="/usr/local/Cellar/node/6.1.0/libexec/npm/bin:$PATH"react-native init appNamecd appNamereact-native run-ios

if you getting xcrun: error: unable to find utility “simctl” at this stage you can resolve using the below steps

如果您得到xcrun:错误:在此阶段无法找到实用程序“ simctl” ,则可以使用以下步骤解决

XCode -> Preferences -> Locations -> Command Line Tools -> Choose Xcode 7.2.1

XCode->首选项->位置->命令行工具->选择Xcode 7.2.1

You can find the original solution from xcrun unable to find simctl

您可以从无法找到Simctl的xcrun中找到原始解决方案

“ run-android”卡在JS Metro Bundler上— 2(“run-android” stuck on JS Metro Bundler — 2)

Sometimes app stuck at loading 7.7%(14) modules like that due to bundle was building slowly. for that, run react-native run android again, and it will work.

有时,由于捆绑构建缓慢,应用程序无法loading 7.7%(14)模块。 为此,再次运行react-native run android ,它将起作用。

错误:EMFILE:打开的文件太多— React Native CLI (Error: EMFILE: too many open files — React Native CLI)

Just close all other files and try again. If you are running on android make sure to run cd android and ./gradlew clean before react-native run-android. If this doesn't fix, there might be a problem with your file watching service. Try this

请关闭所有其他文件,然后重试。 如果您在android上运行,请确保在react-native run-android之前先运行cd android./gradlew clean 。 如果此方法不能解决,则文件监视服务可能存在问题。 尝试这个

$ brew update$ brew install watchman

在OSX上运行./gradlew时,JAVA_HOME设置为无效目录 (JAVA_HOME is set to an invalid directory while running ./gradlew on OSX)

Check if /usr/libexec/java_home exists. If it does then try running

检查/ usr / libexec / java_home是否存在。 如果有,请尝试运行

export JAVA_HOME=`/usr/libexec/java_home`

and rerunning your gradlew build. If it works then make it permanent with

并重新运行gradlew构建。 如果可行,请永久使用

echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.bash_profile

无法安装android-sdk:“ java.lang.NoClassDefFoundError:javax / xml / bind / annotation / XmlSchema” (Failed to install android-sdk: “java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema”)

had a similar problem this morning (trying to build for Android using Unity3D). I ended up uninstalling JDK9 and installing Java SE Development Kit 8u144. Hope this helps.

今天早上也遇到了类似的问题(试图使用Unity3D为Android构建)。 我最终卸载了JDK9并安装了Java SE Development Kit 8u144 。 希望这可以帮助。

  1. brew cask uninstall java # uninstall java9

    brew cask uninstall java cask brew cask uninstall java #卸载java9

  2. brew tap homebrew/cask-versions

    brew tap homebrew/cask-versions

  3. brew cask install java8 # install java8

    brew cask install java8 #安装java8

  4. touch ~/.android/repositories.cfg # without this file, an error will occur on the next step

    如果没有此文件,请touch ~/.android/repositories.cfg #,下一步将发生错误

  5. brew cask install android-sdk

    brew cask install android-sdk

资料来源 (Sources)

翻译自: https://medium.com/weekly-webtips/common-react-native-errors-6cd361892684

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/840808
推荐阅读
相关标签
  

闽ICP备14008679号