Ubuntu React Native 环境搭建

Ubuntu React Native 环境搭建

本人环境是Ubuntu 64位 14.0.4 .

安装 node.js
过程:
  • 1.到node官网下载https://nodejs.org/en/
  • 2.将node-v4.4.4-linux-x64.tar.xz 下载到的 文件解压到自己的目录.
  • 3.将node配置成环境变量如下
export NODE_HOME=/home/djh/djh/node-v4.4.4-linux-x64
export PATH=$NODE_HOME/bin:$PATH

在终端输入 node -v 如下出现版本号则说明安装成功

djh@djh-All-Series:~$ node -v
v4.4.4
问题:

这个步骤简单 暂时没有出现任何问题.

安装 watchman
过程:

安装依赖

$ sudo apt-get install autoconf  automake python-dev

安装 watchman, 如果出错, 查看安装依赖的详细文档

$ git clone https://github.com/facebook/watchman.git
$ cd watchman
$ git checkout v4.3.0  # the latest stable release
$ ./autogen.sh
$ ./configure
$ make
$ sudo make install
问题:

这个步骤简单 暂时没有出现任何问题.如果有问题可以参考文档

安装 react-native
过程:
$ npm install -g react-native-cli
问题:

这个步骤简单 暂时没有出现任何问题.

创建helloworld项目
过程:

$ react-native init HelloWorld

问题:
This will walk you through creating a new React Native project in /home/djh/ReactNativeProject/HelloWorld
Installing react-native package from npm...

这个创建需要点时间,耐心等待.

运行helloworld
过程:
djh@djh-All-Series:~/ReactNativeProject$ cd HelloWorld/
djh@djh-All-Series:~/ReactNativeProject/HelloWorld$  react-native start
问题:
ERROR  Packager can't listen on port 8081

1 如果遇到这个错误说明有个服务已经在运行了,先关闭它

ERROR  A non-recoverable condition has triggered.  Watchman needs your help!
The triggering condition was at timestamp=1463647475: inotify-add-watch(/home/djh/ReactNativeProject/HelloWorld/node_modules/react-native/node_modules/jstransform/node_modules/commoner/node_modules/iconv-lite/encodings/tables) -> The user limit on the total number of inotify watches was reached; increase the fs.inotify.max_user_watches sysctl
All requests will continue to fail with this message until you resolve
the underlying problem.  You will find more information on fixing this at
https://facebook.github.io/watchman/docs/troubleshooting.html#poison-inotify-add-watch

{"watchmanResponse":{"version":"4.3.0","error":"A non-recoverable condition has triggered.  Watchman needs your help!\nThe triggering condition was at timestamp=1463647475: inotify-add-watch(/home/djh/ReactNativeProject/HelloWorld/node_modules/react-native/node_modules/jstransform/node_modules/commoner/node_modules/iconv-lite/encodings/tables) -> The user limit on the total number of inotify watches was reached; increase the fs.inotify.max_user_watches sysctl\nAll requests will continue to fail with this message until you resolve\nthe underlying problem.  You will find more information on fixing this at\nhttps://facebook.github.io/watchman/docs/troubleshooting.html#poison-inotify-add-watch\n"}}
Error: A non-recoverable condition has triggered.  Watchman needs your help!
The triggering condition was at timestamp=1463647475: inotify-add-watch(/home/djh/ReactNativeProject/HelloWorld/node_modules/react-native/node_modules/jstransform/node_modules/commoner/node_modules/iconv-lite/encodings/tables) -> The user limit on the total number of inotify watches was reached; increase the fs.inotify.max_user_watches sysctl
All requests will continue to fail with this message until you resolve
the underlying problem.  You will find more information on fixing this at
https://facebook.github.io/watchman/docs/troubleshooting.html#poison-inotify-add-watch

    at BunserBuf.<anonymous> (/home/djh/ReactNativeProject/HelloWorld/node_modules/react-native/node_modules/sane/node_modules/fb-watchman/index.js:95:23)
    at emitOne (events.js:77:13)
    at BunserBuf.emit (events.js:169:7)
    at BunserBuf.process (/home/djh/ReactNativeProject/HelloWorld/node_modules/react-native/node_modules/bser/index.js:289:10)
    at /home/djh/ReactNativeProject/HelloWorld/node_modules/react-native/node_modules/bser/index.js:244:12
    at nextTickCallbackWith0Args (node.js:420:9)
    at process._tickCallback (node.js:349:13)

2.如果遇到这个问题 解决如下 在终端输入:


echo 256 | sudo tee -a /proc/sys/fs/inotify/max_user_instances

echo 32768 | sudo tee -a /proc/sys/fs/inotify/max_queued_events

echo 65536 | sudo tee -a /proc/sys/fs/inotify/max_user_watches

watchman shutdown-server


官网说这个是watchman的什么个数限制什么的,具体参考 ++https://facebook.github.io/watchman/docs/install.html#system-specific-preparation++

3.因为是第一次弄傻傻的 什么都不懂就在这里一直等,其实服务起来后,就要新开个终端.在这个目录就可以运行到机器了. 这边用的是虚拟机Genymotion

运行apk到android设备
过程:
djh@djh-All-Series:~/ReactNativeProject/HelloWorld$  react-native run-android
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug...
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72301Library
:app:prepareComAndroidSupportRecyclerviewV72301Library
:app:prepareComAndroidSupportSupportV42301Library
:app:prepareComFacebookFrescoDrawee081Library
:app:prepareComFacebookFrescoFbcore081Library
:app:prepareComFacebookFrescoFresco081Library
:app:prepareComFacebookFrescoImagepipeline081Library
:app:prepareComFacebookFrescoImagepipelineOkhttp081Library
:app:prepareComFacebookReactReactNative0260Library
:app:prepareOrgWebkitAndroidJscR174650Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets
:app:generateDebugResValues
:app:generateDebugResources
:app:mergeDebugResources
:app:bundleDebugJsAndAssets SKIPPED
:app:processDebugManifest
:app:processDebugResources


问题:

1.最好先配置好android 的环境和build tool 这里一般需要23.0.1的
++export ANDROID_HOME=/home/djh/djh/adt-bundle-linux-x86_64-20140702/sdk++
如果没有的话使用sdk Manager 下载好.不然会出现很多资源找不到的我问题.

2.第一次运行时间会比较久.

* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: No connected devices!

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

3.遇到上面问题说明没有打开设备,将Genymotion打开.就可以了.
这里写图片描述

修改程序将文字修改成Helloworld
过程

1将工程目录下的 index.android.js 下面一段改改

class HelloWorld extends Component {
  render() {
    return (
      <View style={styles.container}>
          <Text style={styles.reply}>
         Hello world
        </Text>
      </View>
    );
  }
}
问题:

直接按住设备的菜单键 ,选择Reload js 就重新加载了.然后就变成下面的了
这里写图片描述

####后续
将学习运行在真是的手机设备中.

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
React Native 是一个基于 React 的框架,可以用于构建原生应用程序。在开始 React Native 开发之前,需要先搭建相应的开发环境。下面是 React Native 环境搭建的步骤: 1. 安装 Node.js 和 npm React Native 使用 Node.js 和 npm 进行构建和管理依赖。可以从 Node.js 官网下载对应平台的安装包,安装完成后,npm 就会随之安装。 2. 安装 React Native 命令行工具 打开终端或命令行窗口,运行以下命令: ``` npm install -g react-native-cli ``` 这个命令会全局安装 React Native 命令行工具。 3. 安装 Android Studio(仅适用于 Android 平台开发) 如果要进行 Android 平台开发,需要安装 Android Studio。可以从 Android Studio 官网下载对应平台的安装包,安装完成后,启动 Android Studio,并安装相应的 SDK 和 Android 虚拟设备(AVD)。 4. 配置 Android 环境变量(仅适用于 Windows 平台开发) 在 Windows 平台上进行 Android 开发时,需要配置相应的环境变量。可以在系统的“环境变量”中添加以下两个变量: - ANDROID_HOME:指向安装的 Android SDK 的路径 - PATH:在原有的 PATH 变量值后面添加 Android SDK 的 tools 和 platform-tools 目录的路径 5. 创建新项目 在终端或命令行窗口中,进入到要创建项目的目录,运行以下命令: ``` react-native init MyProject ``` 这个命令会创建一个名为 MyProject 的项目,其中包含了 React Native 的基本文件。 6. 运行项目 进入到项目的根目录,运行以下命令: ``` react-native run-android ``` 这个命令会启动 Android 模拟器,并在模拟器上运行项目。如果要在真机上运行项目,需要先将手机连接到电脑,并按照官方文档的说明进行配置。 以上就是 React Native 环境搭建的步骤,希望对你有所帮助。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

沈万三djh

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值