mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-18 01:16:09 +08:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
8b31779b07 | ||
![]() |
84fde13a79 | ||
![]() |
1e9650478d | ||
![]() |
7e11356cb9 | ||
![]() |
0eaf27aea9 |
12
README.md
12
README.md
@@ -2,18 +2,6 @@
|
|||||||
|
|
||||||
本组件是面向 React Native 提供热更新功能的组件,建议结合[Update 服务](https://update.reactnative.cn/)使用。
|
本组件是面向 React Native 提供热更新功能的组件,建议结合[Update 服务](https://update.reactnative.cn/)使用。
|
||||||
|
|
||||||
### 版本
|
|
||||||
|
|
||||||
因为 React Native 不同版本代码结构不同,因而请按下面表格对号入座:
|
|
||||||
|
|
||||||
| React Native 版本 | react-native-update 版本 |
|
|
||||||
| ----------------- | ------------------------ |
|
|
||||||
| 0.26 及以下 | 1.0.x |
|
|
||||||
| 0.27 - 0.28 | 2.x |
|
|
||||||
| 0.29 - 0.33 | 3.x |
|
|
||||||
| 0.34 - 0.45 | 4.x |
|
|
||||||
| 0.46 及以上 | 5.x |
|
|
||||||
|
|
||||||
### 优势
|
### 优势
|
||||||
|
|
||||||
1. 命令行工具&网页双端管理,版本发布过程简单便捷,完全可以集成 CI。
|
1. 命令行工具&网页双端管理,版本发布过程简单便捷,完全可以集成 CI。
|
||||||
|
@@ -6,34 +6,32 @@
|
|||||||
|
|
||||||
所以我们也假设你已经拥有了开发React Native应用的一切环境,包括`Node.js`、`npm`、`XCode`、`Android SDK`等等。
|
所以我们也假设你已经拥有了开发React Native应用的一切环境,包括`Node.js`、`npm`、`XCode`、`Android SDK`等等。
|
||||||
|
|
||||||
如果React Native的版本是0.45以下,并且你之前没安装过,你还必须安装[Android NDK](http://androiddevtools.cn),版本最好选用r10e,并设置环境变量`ANDROID_NDK_HOME`,指向你的NDK根目录(例如`/Users/tdzl2003/Downloads/android-ndk-r10e`)。0.46以上的React Native不需要安装NDK。
|
|
||||||
|
|
||||||
## 安装
|
## 安装
|
||||||
|
|
||||||
在你的项目根目录下运行以下命令:
|
在你的项目根目录下运行以下命令:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm i -g react-native-update-cli
|
npm i -g react-native-update-cli
|
||||||
npm i react-native-update@具体版本请看下面的表格
|
npm i react-native-update
|
||||||
```
|
```
|
||||||
|
|
||||||
如果你的RN版本 < 0.60,那么还需要运行
|
> 如果下载极慢或者显示网络失败,请设置使用淘宝镜像`npx nrm use taobao`
|
||||||
|
|
||||||
|
如果你的RN版本 >= 0.60,请在iOS目录下执行:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
react-native link react-native-update
|
pod install
|
||||||
```
|
```
|
||||||
|
|
||||||
* 注意 *
|
如果你的RN版本 < 0.60,那么还需要[手动link](#一手动link)
|
||||||
|
|
||||||
如果访问极慢或者显示网络失败,请设置使用淘宝镜像(也仅需设置一次):
|
|
||||||
```bash
|
|
||||||
npm install -g nrm
|
|
||||||
nrm use taobao
|
|
||||||
```
|
|
||||||
|
|
||||||
### 版本
|
<details>
|
||||||
|
<summary>
|
||||||
|
如果你的RN版本比较老(< 0.46),请点击这里的注意事项
|
||||||
|
</summary>
|
||||||
|
|
||||||
因为React Native不同版本代码结构不同,因而请按下面表格对号入座:
|
如果你的RN版本比较老,请按下面表格尝试老一些的版本(但这些版本我们已不再维护,不能保证可以使用):
|
||||||
|
|
||||||
| React Native版本 | react-native-update版本 |
|
| React Native版本 | react-native-update版本 |
|
||||||
| ---------------- | ----------------------- |
|
| ---------------- | ----------------------- |
|
||||||
@@ -41,28 +39,53 @@ nrm use taobao
|
|||||||
| 0.27 - 0.28 | 2.x |
|
| 0.27 - 0.28 | 2.x |
|
||||||
| 0.29 - 0.33 | 3.x |
|
| 0.29 - 0.33 | 3.x |
|
||||||
| 0.34 - 0.45 | 4.x |
|
| 0.34 - 0.45 | 4.x |
|
||||||
| 0.46及以上 | 5.x |
|
|
||||||
|
|
||||||
|
|
||||||
安装命令示例:
|
安装命令示例:
|
||||||
```
|
```
|
||||||
npm i react-native-update@5.x
|
npm i react-native-update@4.x
|
||||||
```
|
```
|
||||||
|
|
||||||
|
如果RN的版本是0.45及以下,你还必须安装[Android NDK](http://androiddevtools.cn),版本最好选用r10e,并设置环境变量`ANDROID_NDK_HOME`,指向你的NDK根目录(例如`/Users/tdzl2003/Downloads/android-ndk-r10e`)。
|
||||||
|
</details>
|
||||||
|
|
||||||
|
|
||||||
|
请记得一定要重新编译(react-native run-ios或run-android命令编译,或在Xcode/Android Studio中重新编译)。
|
||||||
|
|
||||||
|
|
||||||
## 一、手动link
|
## 一、手动link
|
||||||
|
|
||||||
如果RN版本 >= 0.60,或是`react-native link`执行成功(iOS工程和安卓工程均能看到依赖),则可以跳过此步骤
|
如果RN版本 >= 0.60则可以跳过此步骤
|
||||||
|
|
||||||
### iOS
|
### iOS
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>RN < 0.60且使用CocoaPods(推荐)</summary>
|
||||||
|
|
||||||
|
1. 在ios/Podfile中添加
|
||||||
|
```
|
||||||
|
pod 'react-native-update', path: '../node_modules/react-native-update'
|
||||||
|
```
|
||||||
|
2. 在项目的ios目录下运行`pod install`
|
||||||
|
3. 重新编译
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>RN < 0.60且不使用CocoaPods</summary>
|
||||||
|
|
||||||
1. 在XCode中的Project Navigator里,右键点击`Libraries` ➜ `Add Files to [你的工程名]`
|
1. 在XCode中的Project Navigator里,右键点击`Libraries` ➜ `Add Files to [你的工程名]`
|
||||||
2. 进入`node_modules` ➜ `react-native-update` ➜ `ios 并选中 `RCTHotUpdate.xcodeproj`
|
2. 进入`node_modules` ➜ `react-native-update` ➜ `ios 并选中 `RCTHotUpdate.xcodeproj`
|
||||||
3. 在XCode中的project navigator里,选中你的工程,在 `Build Phases` ➜ `Link Binary With Libraries` 中添加 `libRCTHotUpdate.a`
|
3. 在XCode中的project navigator里,选中你的工程,在 `Build Phases` ➜ `Link Binary With Libraries` 中添加 `libRCTHotUpdate.a`
|
||||||
4. 继续在`Build Settings`里搜索`Header Search Path`,添加$(SRCROOT)/../node_modules/react-native-update/ios
|
4. 继续在`Build Settings`里搜索`Header Search Path`,添加$(SRCROOT)/../node_modules/react-native-update/ios
|
||||||
5. Run your project (`Cmd+R`)
|
5. 重新编译
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
### Android
|
### Android
|
||||||
|
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>RN < 0.60</summary>
|
||||||
1. 在`android/settings.gradle`中添加如下代码:
|
1. 在`android/settings.gradle`中添加如下代码:
|
||||||
```
|
```
|
||||||
include ':react-native-update'
|
include ':react-native-update'
|
||||||
@@ -77,6 +100,7 @@ npm i react-native-update@5.x
|
|||||||
3. 打开`android/app/src/main/java/[...]/MainApplication.java`,
|
3. 打开`android/app/src/main/java/[...]/MainApplication.java`,
|
||||||
- 在文件开头增加 `import cn.reactnative.modules.update.UpdatePackage;`
|
- 在文件开头增加 `import cn.reactnative.modules.update.UpdatePackage;`
|
||||||
- 在`getPackages()` 方法中增加 `new UpdatePackage()`(注意上一行可能要增加一个逗号)
|
- 在`getPackages()` 方法中增加 `new UpdatePackage()`(注意上一行可能要增加一个逗号)
|
||||||
|
</details>
|
||||||
|
|
||||||
## 二、配置Bundle URL
|
## 二、配置Bundle URL
|
||||||
|
|
||||||
|
@@ -9,7 +9,7 @@ import { ZipFile } from 'yazl';
|
|||||||
import { open as openZipFile } from 'yauzl';
|
import { open as openZipFile } from 'yauzl';
|
||||||
import { question } from './utils';
|
import { question } from './utils';
|
||||||
import { checkPlatform } from './app';
|
import { checkPlatform } from './app';
|
||||||
const { spawn, spawnSync } = require('child_process');
|
const { spawn, spawnSync, execSync } = require('child_process');
|
||||||
const g2js = require('gradle-to-js/lib/parser');
|
const g2js = require('gradle-to-js/lib/parser');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
|
|
||||||
@@ -56,6 +56,7 @@ async function runReactNativeBundleCommand(
|
|||||||
fs.emptyDirSync(outputFolder);
|
fs.emptyDirSync(outputFolder);
|
||||||
|
|
||||||
Array.prototype.push.apply(reactNativeBundleArgs, [
|
Array.prototype.push.apply(reactNativeBundleArgs, [
|
||||||
|
'bundle',
|
||||||
'--assets-dest',
|
'--assets-dest',
|
||||||
outputFolder,
|
outputFolder,
|
||||||
'--bundle-output',
|
'--bundle-output',
|
||||||
@@ -76,18 +77,29 @@ async function runReactNativeBundleCommand(
|
|||||||
reactNativeBundleArgs.push('--config', config);
|
reactNativeBundleArgs.push('--config', config);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const reactNativeBundleProcess = spawn('react-native', reactNativeBundleArgs);
|
||||||
exec(`
|
console.log(`Running bundle command: react-native ${reactNativeBundleArgs.join(' ')}`);
|
||||||
echo Running "react-native bundle" command:
|
|
||||||
react-native bundle ${reactNativeBundleArgs.join(' ')}
|
return new Promise((resolve, reject) => {
|
||||||
`);
|
reactNativeBundleProcess.stdout.on('data', data => {
|
||||||
if (platform === 'android') {
|
console.log(data.toString().trim());
|
||||||
await compileHermesByteCode(bundleName, outputFolder);
|
});
|
||||||
}
|
|
||||||
} catch (e) {
|
reactNativeBundleProcess.stderr.on('data', data => {
|
||||||
console.log(e);
|
console.error(data.toString().trim());
|
||||||
process.exit(1);
|
});
|
||||||
}
|
|
||||||
|
reactNativeBundleProcess.on('close', async exitCode => {
|
||||||
|
if (exitCode) {
|
||||||
|
reject(new Error(`"react-native bundle" command exited with code ${exitCode}.`));
|
||||||
|
} else {
|
||||||
|
if (platform === 'android') {
|
||||||
|
await compileHermesByteCode(bundleName, outputFolder);
|
||||||
|
}
|
||||||
|
resolve(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getHermesOSBin() {
|
function getHermesOSBin() {
|
||||||
@@ -110,11 +122,12 @@ async function compileHermesByteCode(bundleName, outputFolder) {
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
if (enableHermes) {
|
if (enableHermes) {
|
||||||
console.log(`Hermes enabled, now compiling to hermes bytecode:\n`);
|
console.log(`Hermes enabled, now compiling to hermes bytecode:\n`);
|
||||||
const hermesPath = fs.existsSync('node_modules/hermes-engine') ? 'node_modules/hermes-engine' : 'node_modules/hermesvm';
|
const hermesPath = fs.existsSync('node_modules/hermes-engine')
|
||||||
exec(`
|
? 'node_modules/hermes-engine'
|
||||||
${hermesPath}/${getHermesOSBin()}/hermes -emit-binary -out ${outputFolder}/${bundleName} ${outputFolder}/${bundleName} -O
|
: 'node_modules/hermesvm';
|
||||||
echo Compiling done.
|
execSync(
|
||||||
`);
|
`${hermesPath}/${getHermesOSBin()}/hermes -emit-binary -out ${outputFolder}/${bundleName} ${outputFolder}/${bundleName} -O`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-update",
|
"name": "react-native-update",
|
||||||
"version": "5.2.4",
|
"version": "5.2.5",
|
||||||
"description": "react-native hot update",
|
"description": "react-native hot update",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
Reference in New Issue
Block a user