美文网首页
react-native Ubuntu环境搭建

react-native Ubuntu环境搭建

作者: Spirituality韬 | 来源:发表于2018-08-15 09:53 被阅读0次

之前一直在Windows虚拟机上配置环境,也不知道是虚拟机问题,还是什么,AndroidStudio build gradle一直报错

Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.3.1/gradle-4.3.1.pom'. Received status code 400 from server: Bad Request
Enable Gradle 'offline mode' and sync project

之后就想办法在Ubuntu上面搭建react-native环境

sudo apt-get install -y nodejs
sudo ln -s /usr/bin/nodejs /usr/bin/node
sudo apt-get install -y automake python-dev

//安装watchman
git clone https://github.com/facebook/watchman.git
cd watchman
git checkout v4.5.0  # the latest stable release
./autogen.sh
./configure
make
sudo make install

//安装npm
sudo apt-get install npm

//安装flow
sudo npm install -g flow-bin
sudo npm install -g react-native-cli

搭建好环境之后react-native init HelloProject,来建立自己的第一个项目,报错了

/usr/local/lib/node_modules/react-native-cli/index.js:266
const rnPackage = options.version;
^^^^^
SyntaxError: Use of const in strict mode.
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
   at node.js:902:3

据说node版本的问题,https://nodejs.org/zh-cn/ 于是从官网下载高版本的,

tar -xvf node-v8.11.4-linux-x64.tar.xz
sudo gedit /etc/profile
export NODE_HOME=/home/tao/download/node-v8.11.4-linux-x64
export PATH=$PATH:$NODE_HOME/bin
export NODE_PATH=$NODE_HOME/lib/node_modules

最后切换版本

sudo npm install -g n
sudo n stable
tao@pengtao:/usr/local/n/versions/node/10.8.0$ sudo n use 10.8.0 ./lib/node_modules/npm/node_modules/hawk/lib/server.js

创建项目之后运行通过Android-Studio导入android项目最后运行手机出现红屏报错,React Native unable to load script from assets index.android.bundle on windows
手动在main下建立一个assets文件夹
进入项目的根目录下执行:

react-native bundle --platform Android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
react-native run-android;

相关文章

网友评论

      本文标题:react-native Ubuntu环境搭建

      本文链接:https://www.haomeiwen.com/subject/iaeibftx.html