mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-18 01:26:10 +08:00
Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e59841c074 | ||
![]() |
e26aca2e5c | ||
![]() |
8ec528124f | ||
![]() |
f010f6183a | ||
![]() |
679b02ea73 | ||
![]() |
3b69156c4a | ||
![]() |
5a13f82f2e | ||
![]() |
617fb0c1a2 | ||
![]() |
00c1eac457 | ||
![]() |
84ffaa7f5a | ||
![]() |
1e5d73c0d3 | ||
![]() |
df98736c3b | ||
![]() |
c654022300 | ||
![]() |
8a237845e2 | ||
![]() |
8b31779b07 | ||
![]() |
84fde13a79 | ||
![]() |
1e9650478d | ||
![]() |
7e11356cb9 | ||
![]() |
0eaf27aea9 |
31
CHANGELOG.MD
31
CHANGELOG.MD
@@ -1,31 +0,0 @@
|
||||
|
||||
### 最新更新
|
||||
|
||||
## 5.2.1
|
||||
|
||||
1. 检测如果开启了hermes,则自动编译为hermes字节码格式
|
||||
|
||||
## 5.2.0
|
||||
|
||||
1. 添加typescript声明
|
||||
2. 支持cocoapods
|
||||
|
||||
## 5.1.9
|
||||
|
||||
1. 重写bundle命令以提升版本兼容性
|
||||
2. 改进命令行的输出样式
|
||||
|
||||
|
||||
## 5.1.8
|
||||
|
||||
1. 服务器迁移到https
|
||||
2. android支持64位
|
||||
|
||||
|
||||
## 5.1.6
|
||||
|
||||
解决 Android 热更新后部分图片丢失问题:
|
||||
|
||||
同一个项目中放置了多个完全相同的文件,在 5.1.0 至 5.1.5 之间的版本中,更新后有时会出现其中的部分无法显示。此问题在 5.1.6 版本修复。
|
||||
|
||||
修复此问题涉及原生部分,需要重新打包。
|
53
CHANGELOG.md
Normal file
53
CHANGELOG.md
Normal file
@@ -0,0 +1,53 @@
|
||||
### 最近更新
|
||||
|
||||
## 5.3.0 (2019-09-19)
|
||||
|
||||
1. 替换 apk reader 以避免某些环境读取 apk 版本号报错的问题
|
||||
|
||||
## 5.2.9 (2019-09-18)
|
||||
|
||||
1. 添加 proguard 混淆规则以解决开启混淆后闪退的问题
|
||||
|
||||
## 5.2.8
|
||||
|
||||
1. 解决某些情形下 Android 调用 switchVersion 不能重启的问题
|
||||
|
||||
## 5.2.7
|
||||
|
||||
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 字节码格式
|
||||
|
||||
## 5.2.0
|
||||
|
||||
1. 添加 typescript 声明
|
||||
2. 支持 cocoapods
|
||||
|
||||
## 5.1.9
|
||||
|
||||
1. 重写 bundle 命令以提升版本兼容性
|
||||
2. 改进命令行的输出样式
|
||||
|
||||
## 5.1.8
|
||||
|
||||
1. 服务器迁移到 https
|
||||
2. android 支持 64 位
|
||||
|
||||
## 5.1.6
|
||||
|
||||
解决 Android 热更新后部分图片丢失问题:
|
||||
|
||||
同一个项目中放置了多个完全相同的文件,在 5.1.0 至 5.1.5 之间的版本中,更新后有时会出现其中的部分无法显示。此问题在 5.1.6 版本修复。
|
||||
|
||||
修复此问题涉及原生部分,需要重新打包。
|
12
README.md
12
README.md
@@ -2,17 +2,9 @@
|
||||
|
||||
本组件是面向 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 |
|
||||
请查阅[最近更新文档](CHANGELOG.md)。
|
||||
|
||||
### 优势
|
||||
|
||||
|
@@ -14,6 +14,7 @@ android {
|
||||
targetSdkVersion safeExtGet('targetSdkVersion', 27)
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
consumerProguardFiles "proguard.pro"
|
||||
}
|
||||
sourceSets {
|
||||
main {
|
||||
|
2
android/proguard.pro
vendored
Normal file
2
android/proguard.pro
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
-keepnames class cn.reactnative.modules.update.DownloadTask { *; }
|
||||
-keepnames class com.facebook.react.ReactInstanceManager { *; }
|
@@ -135,13 +135,12 @@ public class UpdateModule extends ReactContextBaseJavaModule{
|
||||
loadField.set(instanceManager, loader);
|
||||
}
|
||||
|
||||
final Method recreateMethod = instanceManager.getClass().getMethod("recreateReactContextInBackground");
|
||||
try {
|
||||
instanceManager.recreateReactContextInBackground();
|
||||
} catch(Throwable err) {
|
||||
activity.recreate();
|
||||
}
|
||||
|
||||
final ReactInstanceManager finalizedInstanceManager = instanceManager;
|
||||
|
||||
recreateMethod.invoke(finalizedInstanceManager);
|
||||
|
||||
activity.recreate();
|
||||
} catch (Throwable err) {
|
||||
Log.e("pushy", "Failed to restart application", err);
|
||||
}
|
||||
|
@@ -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`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs-extra';
|
||||
import ApkReader from 'node-apk-parser';
|
||||
const ApkReader = require('adbkit-apkreader');
|
||||
import ipaReader from './ipaReader';
|
||||
|
||||
var read = require('read');
|
||||
@@ -18,10 +18,10 @@ export function question(query, password) {
|
||||
{
|
||||
prompt: query,
|
||||
silent: password,
|
||||
replace: password ? '*' : undefined
|
||||
replace: password ? '*' : undefined,
|
||||
},
|
||||
(err, result) => (err ? reject(err) : resolve(result))
|
||||
)
|
||||
(err, result) => (err ? reject(err) : resolve(result)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -48,14 +48,14 @@ export function getRNVersion() {
|
||||
return {
|
||||
version,
|
||||
major: match[1] | 0,
|
||||
minor: match[2] | 0
|
||||
minor: match[2] | 0,
|
||||
};
|
||||
}
|
||||
|
||||
export function getApkVersion(fn) {
|
||||
const reader = ApkReader.readFile(fn);
|
||||
const manifest = reader.readManifestSync();
|
||||
return Promise.resolve(manifest.versionName);
|
||||
export async function getApkVersion(fn) {
|
||||
const reader = await ApkReader.open(fn);
|
||||
const manifest = await reader.readManifest();
|
||||
return manifest.versionName;
|
||||
}
|
||||
|
||||
export function getIPAVersion(fn) {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update",
|
||||
"version": "5.2.4",
|
||||
"version": "5.3.0",
|
||||
"description": "react-native hot update",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
@@ -28,13 +28,13 @@
|
||||
},
|
||||
"homepage": "https://github.com/reactnativecn/react-native-pushy#readme",
|
||||
"dependencies": {
|
||||
"adbkit-apkreader": "^3.1.2",
|
||||
"cli-arguments": "^0.2.1",
|
||||
"decompress-zip": "^0.3.1",
|
||||
"fs-extra": "^8.1.0",
|
||||
"glob": "^7.1.2",
|
||||
"gradle-to-js": "^2.0.0",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
"node-apk-parser": "^0.2.3",
|
||||
"progress": "^1.1.8",
|
||||
"read": "^1.0.7",
|
||||
"request": "^2.69.0",
|
||||
|
38
yarn.lock
38
yarn.lock
@@ -14,9 +14,14 @@ acorn@^3.1.0:
|
||||
version "3.3.0"
|
||||
resolved "http://registry.npm.taobao.org/acorn/download/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a"
|
||||
|
||||
adm-zip@~0.4.4:
|
||||
version "0.4.7"
|
||||
resolved "http://registry.npm.taobao.org/adm-zip/download/adm-zip-0.4.7.tgz#8606c2cbf1c426ce8c8ec00174447fd49b6eafc1"
|
||||
adbkit-apkreader@^3.1.2:
|
||||
version "3.1.2"
|
||||
resolved "https://registry.yarnpkg.com/adbkit-apkreader/-/adbkit-apkreader-3.1.2.tgz#86a0c676870aba2f16d0f0948d2c94af58417bd5"
|
||||
integrity sha512-xFlRkjEuJ8+hEo6BfUWXyaxDm54RtLCBBC4TzYc1S0SQqrE7r31QWfYaUlJH+eJiPGTUzUCd+SUs1cJaCkATnQ==
|
||||
dependencies:
|
||||
bluebird "^3.4.7"
|
||||
debug "~0.7.4"
|
||||
yauzl "^2.7.0"
|
||||
|
||||
align-text@^0.1.1, align-text@^0.1.3:
|
||||
version "0.1.4"
|
||||
@@ -562,6 +567,11 @@ bluebird@^2.9.33:
|
||||
version "2.11.0"
|
||||
resolved "http://registry.npm.taobao.org/bluebird/download/bluebird-2.11.0.tgz#534b9033c022c9579c56ba3b3e5a5caafbb650e1"
|
||||
|
||||
bluebird@^3.4.7:
|
||||
version "3.5.5"
|
||||
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.5.tgz#a8d0afd73251effbbd5fe384a77d73003c17a71f"
|
||||
integrity sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w==
|
||||
|
||||
boom@2.x.x:
|
||||
version "2.10.1"
|
||||
resolved "http://registry.npm.taobao.org/boom/download/boom-2.10.1.tgz#39c8918ceff5799f83f9492a848f625add0c766f"
|
||||
@@ -1002,6 +1012,13 @@ fd-slicer@~1.0.1:
|
||||
dependencies:
|
||||
pend "~1.2.0"
|
||||
|
||||
fd-slicer@~1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/fd-slicer/-/fd-slicer-1.1.0.tgz#25c7c89cb1f9077f8891bbe61d8f390eae256f1e"
|
||||
integrity sha1-JcfInLH5B3+IkbvmHY85Dq4lbx4=
|
||||
dependencies:
|
||||
pend "~1.2.0"
|
||||
|
||||
filename-regex@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "http://registry.npm.taobao.org/filename-regex/download/filename-regex-2.0.0.tgz#996e3e80479b98b9897f15a8a58b3d084e926775"
|
||||
@@ -1751,13 +1768,6 @@ nice-try@^1.0.4:
|
||||
resolved "https://registry.npm.taobao.org/nice-try/download/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
|
||||
integrity sha1-ozeKdpbOfSI+iPybdkvX7xCJ42Y=
|
||||
|
||||
node-apk-parser@^0.2.3:
|
||||
version "0.2.3"
|
||||
resolved "http://registry.npm.taobao.org/node-apk-parser/download/node-apk-parser-0.2.3.tgz#385a141a6da38de562e5d9f08961bf9724d35fc4"
|
||||
dependencies:
|
||||
adm-zip "~0.4.4"
|
||||
debug "~0.7.4"
|
||||
|
||||
node-fetch@^1.0.1:
|
||||
version "1.6.3"
|
||||
resolved "http://registry.npm.taobao.org/node-fetch/download/node-fetch-1.6.3.tgz#dc234edd6489982d58e8f0db4f695029abcd8c04"
|
||||
@@ -2625,6 +2635,14 @@ yauzl@2.4.1:
|
||||
dependencies:
|
||||
fd-slicer "~1.0.1"
|
||||
|
||||
yauzl@^2.7.0:
|
||||
version "2.10.0"
|
||||
resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9"
|
||||
integrity sha1-x+sXyT4RLLEIb6bY5R+wZnt5pfk=
|
||||
dependencies:
|
||||
buffer-crc32 "~0.2.3"
|
||||
fd-slicer "~1.1.0"
|
||||
|
||||
yazl@2.3.0:
|
||||
version "2.3.0"
|
||||
resolved "http://registry.npm.taobao.org/yazl/download/yazl-2.3.0.tgz#63a6f327b00d09ecdca347af4f3d422fcbca3557"
|
||||
|
Reference in New Issue
Block a user