React-Native 十:版本升级

更新版本的React Native将会让你访问更多的APIs, 这样我们可以去使用更多的APIs,视图Views,以及开发者工具以及其他一些好用的东西。浏览版本更新日志就会发现整体FB官方开发进度还是非常紧张的,这样就很容易导致旧版本会出现不能用的情况,后期可能会出现不可预料的情况,这边建议大家尽量更新最新正式版本。

我们大家都知道一个React Native项目使用Android项目,iOS项目和JavaScript项目三部分进行组成的,而且三者都关联打包在npm包内的,所以该项目版本进行更新是比较繁琐的。下面我来给大家讲解一下React Native项目的升级步骤。

一、查看当前版本

[email protected]:~/AwesomeProject$ react-native --version
react-native-cli: 0.2.0
react-native: 0.22.2

二、查看最新的版本

[email protected]:~/AwesomeProject$ npm info react-native
{ name: ‘react-native‘,
  ‘dist-tags‘: { latest: ‘0.25.1‘, next: ‘0.26.0-rc‘ },
  versions:
   [ ‘0.0.0‘,
     ‘0.0.5‘,
      ... ...
     ‘0.24.1‘,
     ‘0.25.0-rc‘,
     ‘0.25.1‘,
     ‘0.26.0-rc‘ ],
  maintainers:
  ... ...
  dist:
   { shasum: ‘4177e70e56281cec8fb5fe76218bf6606eeb34b8‘,
     tarball: ‘https://registry.npmjs.org/react-native/-/react-native-0.25.1.tgz‘ },
  directories: {} }

三、升级依赖的版本

[email protected]:~/AwesomeProject$ npm install --save [email protected]

> [email protected] install /home/pengchengxiang/AwesomeProject/node_modules/react-native/node_modules/ws/node_modules/bufferutil
> node-gyp rebuild

make: Entering directory `/home/pengchengxiang/AwesomeProject/node_modules/react-native/node_modules/ws/node_modules/bufferutil/build‘
  CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
  SOLINK_MODULE(target) Release/obj.target/bufferutil.node
  COPY Release/bufferutil.node
make: Leaving directory `/home/pengchengxiang/AwesomeProject/node_modules/react-native/node_modules/ws/node_modules/bufferutil/build‘

> [email protected] install /home/pengchengxiang/AwesomeProject/node_modules/react-native/node_modules/ws/node_modules/utf-8-validate
> node-gyp rebuild

make: Entering directory `/home/pengchengxiang/AwesomeProject/node_modules/react-native/node_modules/ws/node_modules/utf-8-validate/build‘
  CXX(target) Release/obj.target/validation/src/validation.o
  SOLINK_MODULE(target) Release/obj.target/validation.node
  COPY Release/validation.node
make: Leaving directory `/home/pengchengxiang/AwesomeProject/node_modules/react-native/node_modules/ws/node_modules/utf-8-validate/build‘

> [email protected] postinstall /home/pengchengxiang/AwesomeProject/node_modules/react-native/node_modules/yeoman-generator/node_modules/cross-spawn/node_modules/spawn-sync
> node postinstall

npm WARN optional dep failed, continuing [email protected]
[email protected] node_modules/react-native
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

提示1:如果在安装的过程中,报错如下

[email protected]:~/ReactNativeWorkspace/AwesomeProject$ npm install --save [email protected]

npm ERR! tar.unpack error reading /home/pengcx/.npm/babel-runtime/6.6.1/package.tgz

npm ERR! tar.unpack error reading /home/pengcx/.npm/babel-runtime/6.6.1/package.tgz

npm ERR! tar.unpack error reading /home/pengcx/.npm/object-assign/4.1.0/package.tgz

npm WARN optional dep failed, continuing [email protected]

npm ERR! tar.unpack error reading /home/pengcx/.npm/babel-runtime/6.6.1/package.tgz

npm ERR! tar.unpack error reading /home/pengcx/.npm/path-exists/1.0.0/package.tgz

npm WARN optional dep failed, continuing [email protected]

npm ERR! Linux 3.13.0-85-generic

npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "--save" "[email protected]"

npm ERR! node v4.4.3

npm ERR! npm  v2.15.1

npm ERR! 0-byte tarball

npm ERR! Please run `npm cache clean`

npm ERR!

npm ERR! If you need help, you may report this error at:

npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:

npm ERR!     /home/pengcx/ReactNativeWorkspace/AwesomeProject/npm-debug.log

处理:npm cache clean

四、更新你项目的template文件

新的npm包会包含更新在运行react-nativeinit命令生成的一些动态文件,例如init创建项目的时候会生成iOS和Android的子项目,我们可以通过以下的命令进行获取最新的代码:

[email protected]:~/AwesomeProject$ react-native upgrade
Upgrading project to react-native v0.25.1
Be sure to read the release notes and breaking changes:
https://github.com/facebook/react-native/releases/tag/v0.25.0
 conflict .gitignore
? Overwrite .gitignore? overwrite
    force .gitignore
identical .watchmanconfig
   create .buckconfig
identical ios/AwesomeProject/AppDelegate.h
identical ios/AwesomeProject/AppDelegate.m
identical ios/AwesomeProject/Base.lproj/LaunchScreen.xib
identical ios/AwesomeProject/Images.xcassets/AppIcon.appiconset/Contents.json
identical ios/AwesomeProject/Info.plist
identical ios/AwesomeProject/main.m
 conflict ios/AwesomeProjectTests/AwesomeProjectTests.m
? Overwrite ios/AwesomeProjectTests/AwesomeProjectTests.m? overwrite
    force ios/AwesomeProjectTests/AwesomeProjectTests.m
identical ios/AwesomeProjectTests/Info.plist
identical ios/AwesomeProject.xcodeproj/project.pbxproj
identical ios/AwesomeProject.xcodeproj/xcshareddata/xcschemes/AwesomeProject.xcscheme
 conflict android/build.gradle
? Overwrite android/build.gradle? overwrite
    force android/build.gradle
identical android/gradle.properties
identical android/settings.gradle
   create android/app/BUCK
 conflict android/app/build.gradle
? Overwrite android/app/build.gradle? overwrite
    force android/app/build.gradle
 conflict android/app/proguard-rules.pro
? Overwrite android/app/proguard-rules.pro? overwrite
    force android/app/proguard-rules.pro
identical android/app/src/main/java/com/awesomeproject/MainActivity.java
To run your app on iOS:
   cd /home/pengchengxiang/AwesomeProject
   react-native run-ios
   - or -
   Open /home/pengchengxiang/AwesomeProject/ios/AwesomeProject.xcodeproj in Xcode
   Hit the Run button
To run your app on Android:
   Have an Android emulator running (quickest way to get started), or a device connected
   cd /home/pengchengxiang/AwesomeProject
   react-native run-android

它会检查你的文件,对比最新版本,然后进行如下几个操作:

如果是新添加的文件,会进行直接创建

如果更新的文件和当前项目的文件是一样的,就会直接忽略跳过

如果更新的文件和当前项目的文件不同,有冲突的情况,会让我们进行选择是保留原来的文件还是用更新的文件覆盖,这个要看实际情况了。

时间: 2024-10-14 02:34:07

React-Native 十:版本升级的相关文章

React Native(十五)&mdash;&mdash;RN中的分享功能

终于,终于,可以总结自己使用RN时的分享功能了-- 为什么呢?且听我慢慢道来吧: 从刚开始接触React Native(2017年9月中旬)就着手于分享功能,直到自己参与公司的rn项目开发中,再到现在几乎"竣工"的过程中,这一路的"艰辛"估计也只有自己能体会到了吧.其实自己并不喜欢抱怨,也不喜欢把负能量带给身边的朋友,因此在遇到问题后,都是竭尽全力的攻克它,也许会"废寝忘食",也许是"徒劳无功",即使中间道路实在太曲折,但庆幸

React Native(十四)&mdash;&mdash;Slider小见解

最近我们rn版的App快要内测了,小伙伴们都在积极的改bug,于是在其中就遇到了关于Slider的部分小知识,特地记录自己用到的部分属性,也许恰好会帮助到用到该组件的你: 属性罗列(https://reactnative.cn/docs/0.51/slider.html#content): View props- 继承View的所有属性: 1.disabled:如果为true,用户就不能移动滑块;默认为false; 2.value:滑块的初始值.这个值应该在最小值和最大值之间.默认值是0 仅IO

react native 项目版本升级

首先说明一下rn项目的一种相当顺滑升级方法: 1.全局安装react-native-git-upgrade npm i -g react-native-git-upgrade 2. 在项目目录下执行命令: react-native-git-upgrade over!就是这么简单 问题记录: 最近在升级项目rn版本0.57.1->0.58.5时遇到了一些问题,提示Requires Babel "^7.0.0-0", but was loaded with "6.26.3&

React Native专题-江清清

本React Native讲解专题:主要讲解了React Native开发,由基础环境搭建配置入门,基础,进阶相关讲解. 刚创建的React Native交流8群:533435865  欢迎各位大牛,React Native技术爱好者加入交流!同时博客右侧欢迎微信扫描关注订阅号,移动技术干货,精彩文章技术推送! 关于React Native各种疑难杂症,问题深坑总结方案请点击查看: Mac和Windows安装搭建React Native环境教程如下: Mac OS X版本:Mac OS X安装R

React Native 从零到高级- 0基础学习路线

React Native QQ交流群(美团,饿了么,阿里的大神都在里面):576089067 React Native  从0 基础到高级 视频教程正在重录中,要了解最新进度可以关注菜鸟窝微信公众号(下图),旧版视频教程可以点击这里在线学习 学习路线(文章版),江清清老师出品,点击这里关注江清清 ,同时可以关注一下他的课程 基础入门:1.React Native For Android环境配置以及第一个实例2.React Native开发IDE安装及配置3.React Native应用设备运行(

React Native专题文章讲解,不断更新中.....

转载请标明出处: http://blog.csdn.net/developer_jiangqq/article/details/50633488 本文出自:[江清清的博客] 本React Native讲解专题:主要讲解了React Native开发,由基础环境搭建配置入门,基础,进阶相关讲解. 关于React Native各种疑难杂症,问题深坑总结方案请点击查看: Mac和Windows安装搭建React Native环境教程如下: Mac OS X版本:Mac OS X安装React Nati

React Native专题

刚创建的React Native技术交流1群(282693535),React Native技术交流2群(496601483),React Native技术交流3群(496508742).欢迎各位大牛,React Native技术爱好者加入交流!同时博客右侧欢迎微信扫描关注订阅号,移动技术干货,精彩文章技术推送! 关于React Native各种疑难杂症,问题深坑总结方案请点击查看: Mac和Windows安装搭建React Native环境教程如下: Mac OS X版本:Mac OS X安装

【转】【React Native开发】

[React Native开发]React Native控件之ListView组件讲解以及最齐全实例(19) [React Native开发]React Native控件之Touchable*系列组件详解(18) [React Native开发]React Native控件之ViewPagerAndroid讲解以及美团首页顶部效果实例(17) [React Native开发]React Native控件之Switch开关与Picker选择器组件讲解以及使用(16) [React Native开发

【REACT NATIVE 系列教程之九】REACT NATIVE版本升级步骤与注意事项!

本站文章均为 李华明Himi 原创,转载务必在明显处注明: 转载自[黑米GameDev街区] 原文链接: http://www.himigame.com/react-native/2288.html 由于React Native处于快速迭代发展中,因此组件功能的扩展.语法的变更也将会有较大的区别,因此升级版本则属于务必掌握的了. 昨天Himi刚从0.23版本升级到0.26,升级的主要原因有两点: 1. 一些组件在最新版本中加入了很多新的属性,例如0.23版本中Modal动画没有最新的属性: an

【REACT NATIVE 系列教程之十二】REACT NATIVE(JS/ES)与IOS(OBJECT-C)交互通信

一用到跨平台的引擎必然要有引擎与各平台原生进行交互通信的需要.那么Himi先讲解React Native与iOS之间的通信交互. 本篇主要分为两部分讲解:(关于其中讲解的OC语法等不介绍,不懂的请自行学习) 1. React Native 访问iOS 2. iOS访问React Native     一:React Native 访问iOS 1. 我们想要JS调用OC函数,就要实现一个"RCTBridgeModule"协议的Objective-C类 所以首先我们先创建一个oc新类,