ReactNative环境搭建遇到的那些坑

ReactNative版本0.51

按照官方文档执行一下命令:(node,watchman已经存在)

npm install -g yarn react-native-cli
yarn config set registry https://registry.npm.taobao.org --global
yarn config set disturl https://npm.taobao.org/dist --global
react-native init AwesomeProject
cd AwesomeProject
react-native run-ios
遇到的第一个错误是:error Received malformed response from registry for undefined. The registry may be down.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
{ Error: Command failed: yarn add react-native --exact
    at checkExecSyncError (child_process.js:591:13)
    at execSync (child_process.js:631:13)
    at run (/usr/local/lib/node_modules/react-native-cli/index.js:294:5)
    at createProject (/usr/local/lib/node_modules/react-native-cli/index.js:249:3)
    at init (/usr/local/lib/node_modules/react-native-cli/index.js:200:5)
    at Object.<anonymous> (/usr/local/lib/node_modules/react-native-cli/index.js:153:7)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
  error: null,
  cmd: 'yarn add react-native --exact',
  file: '/bin/sh',
  args: [ '/bin/sh', '-c', 'yarn add react-native --exact' ],
  options:
   { stdio: [ [Object], [Object], [Object] ],
     shell: true,
     file: '/bin/sh',
     args: [ '/bin/sh', '-c', 'yarn add react-native --exact' ],
     envPairs:
      [ 'TERM_PROGRAM=Apple_Terminal',
        'SHELL=/bin/bash',
        'TERM=xterm-256color',
        'TMPDIR=/var/folders/hn/flfx2mnd237974bkycxx4cyr0000gn/T/',
        'Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.doVsJqajaI/Render',
        'TERM_PROGRAM_VERSION=404',
        'TERM_SESSION_ID=3A4EEA90-61EB-4617-8A82-4FD0839E0D7B',
        'USER=mac',
        'SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.SugzQee0nY/Listeners',
        'PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Wireshark.app/Contents/MacOS',
        'PWD=/Users/mac/Desktop',
        'LANG=zh_CN.UTF-8',
        'XPC_FLAGS=0x0',
        'XPC_SERVICE_NAME=0',
        'SHLVL=1',
        'HOME=/Users/mac',
        'LOGNAME=mac',
        '_=/usr/local/bin/react-native',
        'OLDPWD=/Users/mac',
        '__CF_USER_TEXT_ENCODING=0x1F5:0x19:0x34' ],
     killSignal: undefined },
  envPairs:
   [ 'TERM_PROGRAM=Apple_Terminal',
     'SHELL=/bin/bash',
     'TERM=xterm-256color',
     'TMPDIR=/var/folders/hn/flfx2mnd237974bkycxx4cyr0000gn/T/',
     'Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.doVsJqajaI/Render',
     'TERM_PROGRAM_VERSION=404',
     'TERM_SESSION_ID=3A4EEA90-61EB-4617-8A82-4FD0839E0D7B',
     'USER=mac',
     'SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.SugzQee0nY/Listeners',
     'PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Wireshark.app/Contents/MacOS',
     'PWD=/Users/mac/Desktop',
     'LANG=zh_CN.UTF-8',
     'XPC_FLAGS=0x0',
     'XPC_SERVICE_NAME=0',
     'SHLVL=1',
     'HOME=/Users/mac',
     'LOGNAME=mac',
     '_=/usr/local/bin/react-native',
     'OLDPWD=/Users/mac',
     '__CF_USER_TEXT_ENCODING=0x1F5:0x19:0x34' ],
  stderr: null,
  stdout: null,
  pid: 50318,
  output: [ null, null, null ],
  signal: null,
  status: 1 }
Command `yarn add react-native --exact` failed.
macdeMac-mini:Desktop mac$ npm config set registry https://registry.npm.taobao.org

解决方案:

npm config set registry https://registry.npm.taobao.org

npm config set disturl https://npm.taobao.org/dist

顺便删除yarn,删除方法:cd /usr/local/bin   rm yarn   (mac本)

进行第二次尝试:react-native init xxx  又出现问题

npm ERR! code ENOTFOUND
npm ERR! errno ENOTFOUND
npm ERR! network request to https://cdn.npm.taobao.org/abab/-/abab-1.0.4.tgz failed, reason: getaddrinfo ENOTFOUND cdn.npm.taobao.org cdn.npm.taobao.org:443
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/mac/.npm/_logs/2018-05-24T07_42_53_181Z-debug.log
child_process.js:634
    throw err;
    ^

Error: Command failed: npm install jest babel-jest babel-preset-react-native react-test-renderer@16.3.1 --save-dev --save-exact
    at checkExecSyncError (child_process.js:591:13)
    at execSync (child_process.js:631:13)
    at generateProject (/Users/mac/Desktop/AwesomeProject/node_modules/react-native/local-cli/init/init.js:96:7)
    at Object.init (/Users/mac/Desktop/AwesomeProject/node_modules/react-native/local-cli/init/init.js:50:5)
    at run (/usr/local/lib/node_modules/react-native-cli/index.js:302:7)
    at createProject (/usr/local/lib/node_modules/react-native-cli/index.js:249:3)
    at init (/usr/local/lib/node_modules/react-native-cli/index.js:200:5)
    at Object.<anonymous> (/usr/local/lib/node_modules/react-native-cli/index.js:153:7)
    at Module._compile (module.js:573:30)

    at Object.Module._extensions..js (module.js:584:10)

解决方案:降低版本

react-native init MyApp --version 0.41.0(降低到0.44.0以下就OK了)

此时下载源工程没有出错,接下来在真机上运行,运行步骤如下:

1.androidstudio打开工程目录下的android工程

2.webstrom打开工程根目录

3.运行Androidstudio原生功能,使其在手机上运行起来。

4.配置ip 查看电脑ip,晃动手机,在dialog上选择Dev Setting->Debug server host & port for device输入ip填入默认端口8081

5.命令行工具中目录调整到根目录下,输入命令react-native run-android 或者npm start 或者 react-native start

6.晃动手机在dialog选择Reload选项,或者直接点击错误界面下方的Reloada按钮,观察命令行输入。



原生部分错误:

Error:Execution failed for task ':app:mergeDebugResources'. > Error: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:

错误原因:Androidstudio有着对图片的严格检查,工程中存在不符合要求的图片。

解决方案:

  1. android {  
  2.       
  3.    ......  
  4.   
  5.     aaptOptions.cruncherEnabled = false  
  6.     aaptOptions.useNewCruncher = false  
  7.   
  8.    ......  
  9. }
以上就是我遇到的坑,就酱紫~~~
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
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 环境搭建的步骤,希望对你有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值