mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-16 12:51:44 +08:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
df98736c3b | ||
![]() |
c654022300 | ||
![]() |
8a237845e2 | ||
![]() |
8b31779b07 | ||
![]() |
84fde13a79 | ||
![]() |
1e9650478d | ||
![]() |
7e11356cb9 | ||
![]() |
0eaf27aea9 |
13
CHANGELOG.MD
13
CHANGELOG.MD
@@ -1,6 +1,19 @@
|
||||
|
||||
### 最新更新
|
||||
|
||||
## 5.2.5
|
||||
|
||||
1. 改进windows端打更新包的兼容性(部分windows机器上会产生空ppk文件)
|
||||
|
||||
## 5.2.4
|
||||
|
||||
1. 支持RN 0.61的hermes(路径变化)
|
||||
2. iOS端使用第三方的SSZipArchive以减少重名冲突
|
||||
|
||||
## 5.2.2
|
||||
|
||||
1. 修复一处导致iOS回滚的问题
|
||||
|
||||
## 5.2.1
|
||||
|
||||
1. 检测如果开启了hermes,则自动编译为hermes字节码格式
|
||||
|
12
README.md
12
README.md
@@ -2,18 +2,6 @@
|
||||
|
||||
本组件是面向 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。
|
||||
|
@@ -6,34 +6,32 @@
|
||||
|
||||
所以我们也假设你已经拥有了开发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
|
||||
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
|
||||
react-native link react-native-update
|
||||
```
|
||||
|
||||
* 注意 *
|
||||
|
||||
如果访问极慢或者显示网络失败,请设置使用淘宝镜像(也仅需设置一次):
|
||||
```bash
|
||||
npm install -g nrm
|
||||
nrm use taobao
|
||||
pod install
|
||||
```
|
||||
|
||||
### 版本
|
||||
如果你的RN版本 < 0.60,那么还需要[手动link](#一手动link)
|
||||
|
||||
因为React Native不同版本代码结构不同,因而请按下面表格对号入座:
|
||||
|
||||
<details>
|
||||
<summary>
|
||||
如果你的RN版本比较老(< 0.46),请点击这里的注意事项
|
||||
</summary>
|
||||
|
||||
如果你的RN版本比较老,请按下面表格尝试老一些的版本(但这些版本我们已不再维护,不能保证可以使用):
|
||||
|
||||
| React Native版本 | react-native-update版本 |
|
||||
| ---------------- | ----------------------- |
|
||||
@@ -41,28 +39,53 @@ nrm use taobao
|
||||
| 0.27 - 0.28 | 2.x |
|
||||
| 0.29 - 0.33 | 3.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
|
||||
|
||||
如果RN版本 >= 0.60,或是`react-native link`执行成功(iOS工程和安卓工程均能看到依赖),则可以跳过此步骤
|
||||
如果RN版本 >= 0.60则可以跳过此步骤
|
||||
|
||||
### 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 [你的工程名]`
|
||||
2. 进入`node_modules` ➜ `react-native-update` ➜ `ios 并选中 `RCTHotUpdate.xcodeproj`
|
||||
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
|
||||
5. Run your project (`Cmd+R`)
|
||||
5. 重新编译
|
||||
|
||||
</details>
|
||||
|
||||
### Android
|
||||
|
||||
|
||||
<details>
|
||||
<summary>RN < 0.60</summary>
|
||||
1. 在`android/settings.gradle`中添加如下代码:
|
||||
```
|
||||
include ':react-native-update'
|
||||
@@ -77,6 +100,7 @@ npm i react-native-update@5.x
|
||||
3. 打开`android/app/src/main/java/[...]/MainApplication.java`,
|
||||
- 在文件开头增加 `import cn.reactnative.modules.update.UpdatePackage;`
|
||||
- 在`getPackages()` 方法中增加 `new UpdatePackage()`(注意上一行可能要增加一个逗号)
|
||||
</details>
|
||||
|
||||
## 二、配置Bundle URL
|
||||
|
||||
|
@@ -9,7 +9,7 @@ import { ZipFile } from 'yazl';
|
||||
import { open as openZipFile } from 'yauzl';
|
||||
import { question } from './utils';
|
||||
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 os = require('os');
|
||||
|
||||
@@ -56,6 +56,8 @@ async function runReactNativeBundleCommand(
|
||||
fs.emptyDirSync(outputFolder);
|
||||
|
||||
Array.prototype.push.apply(reactNativeBundleArgs, [
|
||||
path.join("node_modules", "react-native", "local-cli", "cli.js"),
|
||||
"bundle",
|
||||
'--assets-dest',
|
||||
outputFolder,
|
||||
'--bundle-output',
|
||||
@@ -76,18 +78,29 @@ async function runReactNativeBundleCommand(
|
||||
reactNativeBundleArgs.push('--config', config);
|
||||
}
|
||||
|
||||
try {
|
||||
exec(`
|
||||
echo Running "react-native bundle" command:
|
||||
react-native bundle ${reactNativeBundleArgs.join(' ')}
|
||||
`);
|
||||
if (platform === 'android') {
|
||||
await compileHermesByteCode(bundleName, outputFolder);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
process.exit(1);
|
||||
}
|
||||
const reactNativeBundleProcess = spawn('node', reactNativeBundleArgs);
|
||||
console.log(`Running bundle command: node ${reactNativeBundleArgs.join(' ')}`);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
reactNativeBundleProcess.stdout.on('data', data => {
|
||||
console.log(data.toString().trim());
|
||||
});
|
||||
|
||||
reactNativeBundleProcess.stderr.on('data', data => {
|
||||
console.error(data.toString().trim());
|
||||
});
|
||||
|
||||
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() {
|
||||
@@ -110,11 +123,12 @@ async function compileHermesByteCode(bundleName, outputFolder) {
|
||||
} catch (e) {}
|
||||
if (enableHermes) {
|
||||
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';
|
||||
exec(`
|
||||
${hermesPath}/${getHermesOSBin()}/hermes -emit-binary -out ${outputFolder}/${bundleName} ${outputFolder}/${bundleName} -O
|
||||
echo Compiling done.
|
||||
`);
|
||||
const hermesPath = fs.existsSync('node_modules/hermes-engine')
|
||||
? 'node_modules/hermes-engine'
|
||||
: 'node_modules/hermesvm';
|
||||
execSync(
|
||||
`${hermesPath}/${getHermesOSBin()}/hermes -emit-binary -out ${outputFolder}/${bundleName} ${outputFolder}/${bundleName} -O`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update",
|
||||
"version": "5.2.4",
|
||||
"version": "5.2.6",
|
||||
"description": "react-native hot update",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
|
Reference in New Issue
Block a user