Skip to content

Commit b4af84a

Browse files
committed
update cpp
1 parent fa9d235 commit b4af84a

File tree

2 files changed

+206
-1
lines changed

2 files changed

+206
-1
lines changed

subs/cpp_native/src/main/assets/patch/readme.md

Lines changed: 204 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,207 @@
1-
- 生成 patch
1+
## 安装 bsdiff
2+
3+
下面按**不同操作系统**给你一份**最常用、最稳妥的 bsdiff 安装方式**
4+
`bsdiff` 本身是一个 C 工具,没有复杂依赖)
5+
6+
---
7+
8+
## 一、macOS 安装(最简单 ✅)
9+
10+
### 方法 1:Homebrew(**强烈推荐**
11+
12+
```bash
13+
brew install bsdiff
14+
```
15+
16+
验证:
17+
18+
```bash
19+
bsdiff --help
20+
bspatch --help
21+
```
22+
23+
安装位置一般是:
24+
25+
```bash
26+
/usr/local/bin/bsdiff
27+
```
28+
29+
---
30+
31+
### 方法 2:源码编译(可控、适合定制)
32+
33+
```bash
34+
git clone https://github.com/mendsley/bsdiff.git
35+
cd bsdiff
36+
make
37+
sudo make install
38+
```
39+
40+
---
41+
42+
## 二、Ubuntu / Debian / Linux 安装
43+
44+
### 方法 1:apt(部分发行版有)
45+
46+
```bash
47+
sudo apt update
48+
sudo apt install bsdiff
49+
```
50+
51+
如果找不到包(很常见),用源码方式 👇
52+
53+
---
54+
55+
### 方法 2:源码编译(通用)
56+
57+
```bash
58+
sudo apt install build-essential
59+
git clone https://github.com/mendsley/bsdiff.git
60+
cd bsdiff
61+
make
62+
sudo cp bsdiff bspatch /usr/local/bin/
63+
```
64+
65+
验证:
66+
67+
```bash
68+
which bsdiff
69+
```
70+
71+
---
72+
73+
## 三、Windows 安装(3 种方式)
74+
75+
### ✅ 方案 1:WSL(最推荐)
76+
77+
```powershell
78+
wsl --install
79+
```
80+
81+
进入 WSL 后:
82+
83+
```bash
84+
sudo apt install bsdiff
85+
```
86+
87+
👉 **最接近 Linux / Android 构建环境**
88+
89+
---
90+
91+
### 方案 2:MinGW 编译
92+
93+
```bash
94+
git clone https://github.com/mendsley/bsdiff.git
95+
cd bsdiff
96+
gcc bsdiff.c -o bsdiff
97+
gcc bspatch.c -o bspatch
98+
```
99+
100+
> 注意:需要 `bzip2``libbz2`
101+
102+
---
103+
104+
### 方案 3:直接下载预编译版(不推荐生产)
105+
106+
* GitHub release
107+
* 第三方工具包
108+
109+
⚠️ **不利于 Android / CI / 自动化**
110+
111+
---
112+
113+
## 四、Android / NDK 环境(非常常见)
114+
115+
### 1️⃣ 编译为 Android 可执行文件
116+
117+
```bash
118+
$NDK/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang \
119+
bspatch.c \
120+
-o bspatch \
121+
--target=aarch64-linux-android21
122+
```
123+
124+
推送到设备:
125+
126+
```bash
127+
adb push bspatch /data/local/tmp/
128+
adb shell chmod +x /data/local/tmp/bspatch
129+
```
130+
131+
---
132+
133+
### 2️⃣ 编译为 JNI(推荐方式)
134+
135+
```text
136+
libbspatch.so
137+
```
138+
139+
Java / Kotlin 调用:
140+
141+
```java
142+
native int bspatch(String oldFile, String newFile, String patch);
143+
```
144+
145+
(如果你需要,我可以直接给你 **完整 NDK + CMake 示例**
146+
147+
---
148+
149+
## 五、Docker(构建 / CI 专用)
150+
151+
```dockerfile
152+
FROM ubuntu:22.04
153+
RUN apt update && apt install -y bsdiff
154+
```
155+
156+
适合:
157+
158+
* GitHub Actions
159+
* 自动生成 patch
160+
161+
---
162+
163+
## 六、验证安装是否成功(必做)
164+
165+
```bash
166+
echo "hello" > a.txt
167+
echo "hello world" > b.txt
168+
169+
bsdiff a.txt b.txt test.patch
170+
bspatch a.txt c.txt test.patch
171+
172+
diff b.txt c.txt
173+
```
174+
175+
无输出 = 成功 ✅
176+
177+
---
178+
179+
## 七、常见安装问题
180+
181+
### ❌ 找不到 bsdiff
182+
183+
```bash
184+
which bsdiff
185+
```
186+
187+
若为空:
188+
189+
```bash
190+
export PATH=/usr/local/bin:$PATH
191+
```
192+
193+
---
194+
195+
### ❌ make 失败(缺 bzip2)
196+
197+
```bash
198+
sudo apt install libbz2-dev
199+
```
200+
201+
---
202+
203+
204+
## 生成 patch
2205

3206
```shell
4207
bsdiff: usage: bsdiff oldfile newfile patchfile

subs/cpp_native/src/main/cpp/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ add_library(
4141
SHARED
4242
bspatch.c)
4343

44+
#add_executable(bs_patch.so, bspatch.c)
45+
4446
# Searches for a specified prebuilt library and stores the path as a
4547
# variable. Because CMake includes system libraries in the search path by
4648
# default, you only need to specify the name of the public NDK library

0 commit comments

Comments
 (0)