Skip to content

Commit 220a2d6

Browse files
authored
Update README.md
1 parent abbb00c commit 220a2d6

1 file changed

Lines changed: 49 additions & 70 deletions

File tree

README.md

Lines changed: 49 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -19,101 +19,80 @@
1919
***8. 支持在Activity/Fragment/View/ViewModel/任意类中,自动关闭请求***
2020

2121
***9. 支持全局加解密、添加公共参数及头部、网络缓存,均支持对某个请求单独设置***
22-
23-
**Gradle依赖**
24-
25-
```java
26-
//以下三个为必须,其它均为非必须
27-
implementation 'com.ljx.rxhttp:rxhttp:2.2.5'
28-
implementation 'com.squareup.okhttp3:okhttp:4.7.2' //rxhttp v2.2.2版本起,需要手动依赖okhttp
29-
annotationProcessor 'com.ljx.rxhttp:rxhttp-compiler:2.2.5' //生成RxHttp类,kotlin用户,请使用kapt替代annotationProcessor
30-
31-
implementation 'com.ljx.rxlife:rxlife-coroutine:2.0.0' //管理协程生命周期,页面销毁,关闭请求
32-
implementation 'com.ljx.rxlife2:rxlife-rxjava:2.0.0' //管理RxJava2生命周期,页面销毁,关闭请求
33-
implementation 'com.ljx.rxlife3:rxlife-rxjava:3.0.0' //管理RxJava3生命周期,页面销毁,关闭请求
34-
35-
//Converter 根据自己需求选择 RxHttp默认内置了GsonConverter
36-
implementation 'com.ljx.rxhttp:converter-jackson:2.2.5'
37-
implementation 'com.ljx.rxhttp:converter-fastjson:2.2.5'
38-
implementation 'com.ljx.rxhttp:converter-protobuf:2.2.5'
39-
implementation 'com.ljx.rxhttp:converter-simplexml:2.2.5'
40-
```
41-
[遇到问题,点击这里,99%的问题都能自己解决](https://github.com/liujingxing/okhttp-RxHttp/wiki/FAQ)
22+
23+
# 上手准备
4224

4325
***RxHttp&RxLife 交流群:378530627***
4426

45-
# 上手准备(必看)
46-
47-
1、RxHttp 要求项目使用Java 8 或更高版本,请在 app 的 build.gradle 添加以下代码
27+
[遇到问题,点击这里,99%的问题都能自己解决](https://github.com/liujingxing/okhttp-RxHttp/wiki/FAQ)
4828

29+
**必须**
4930
```java
50-
compileOptions {
51-
sourceCompatibility JavaVersion.VERSION_1_8
52-
targetCompatibility JavaVersion.VERSION_1_8
53-
}
54-
```
55-
56-
2、OkHttp兼容问题
31+
//使用kapt依赖rxhttp-compiler,需要导入kapt插件
32+
apply plugin: 'kotlin-kapt'
5733

58-
RxHttp目前对OkHttp 的 `v3.12.0 - v4.7.x`均已完成适配工作(v4.3.0除外,该版本有一bug,暂时无法适配),
59-
在你依赖okhttp时,需要告诉rxhttp你依赖的okhttp版本号,如下:
60-
61-
```java
62-
defaultConfig {
63-
javaCompileOptions {
64-
annotationProcessorOptions {
34+
android {
35+
defaultConfig {
36+
javaCompileOptions {
6537
//告知RxHttp你依赖的okhttp版本
66-
arguments = [rxhttp_okhttp: '4.7.2'] //可传入3.12.x至4.7.x任一版本(4.3.0除外)
38+
annotationProcessorOptions {
39+
arguments = [rxhttp_okhttp: 4.7.2]
40+
}
6741
}
6842
}
43+
//java 8或更高
44+
compileOptions {
45+
sourceCompatibility JavaVersion.VERSION_1_8
46+
targetCompatibility JavaVersion.VERSION_1_8
47+
}
6948
}
7049
dependencies {
71-
implementation 'com.squareup.okhttp3:okhttp:4.7.2'
50+
implementation 'com.ljx.rxhttp:rxhttp:2.2.5'
51+
implementation 'com.squareup.okhttp3:okhttp:4.7.2' //rxhttp v2.2.2版本起,需要手动依赖okhttp
52+
kapt 'com.ljx.rxhttp:rxhttp-compiler:2.2.5' //生成RxHttp类,非kotlin项目,请使用annotationProcessor代替kapt
7253
}
7354
```
7455

7556
***注:`OkHttp 3.14.x`以上版本, 最低要求为API 21,如你想要兼容21以下,请依赖`OkHttp 3.12.x`,该版本最低要求 API 9***
7657

77-
3、RxJava兼容问题
78-
79-
RxHttp 2.2.0版本起,内部不在依赖RxJava相关库,采用外挂的方法替代,如你需要结合RxJava发送请求,请单独配置,如下:
80-
58+
最后,***rebuild一下(此步骤是必须的)*** ,就会自动生成RxHttp类,更多配置,请继续往下看
59+
60+
**非必须**
8161
```java
82-
defaultConfig {
83-
javaCompileOptions {
84-
annotationProcessorOptions {
85-
//手动告知RxHttp要使用的RxJava版本,才会生成asXxx方法
86-
arguments = [rxhttp_rxjava: 'rxjava3'] //可传入rxjava2、rxjava3
62+
android {
63+
defaultConfig {
64+
javaCompileOptions {
65+
annotationProcessorOptions {
66+
arguments = [
67+
rxhttp_rxjava: 'rxjava3'//告知RxHttp你依赖的rxjava版本
68+
rxhttp_package: 'rxhttp' //指定RxHttp相关类的生成路径,即包名
69+
]
70+
}
8771
}
8872
}
8973
}
90-
//并自行依赖RxJava相关库,RxJava2/Rxjava3二选一,如下:
74+
// RxJava2/Rxjava3二选一
9175
dependencies {
92-
//rxjava2
93-
implementation 'io.reactivex.rxjava2:rxjava:2.2.8'
94-
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
95-
implementation 'com.ljx.rxlife2:rxlife-rxjava:2.0.0' //管理RxJava2生命周期,页面销毁,关闭请求
96-
97-
//rxjava3
98-
implementation 'io.reactivex.rxjava3:rxjava:3.0.2'
99-
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
100-
implementation 'com.ljx.rxlife3:rxlife-rxjava:3.0.0' //管理RxJava3生命周期,页面销毁,关闭请求
101-
}
102-
```
10376

104-
***注: 如你需要同时指定okhttp及rxjava版本,只需用逗号隔开即可,如下:***
105-
```java
106-
annotationProcessorOptions {
107-
arguments = [
108-
rxhttp_okhttp: '4.7.2',
109-
rxhttp_rxjava: 'rxjava3'
110-
]
77+
implementation 'com.ljx.rxlife:rxlife-coroutine:2.0.0' //管理协程生命周期,页面销毁,关闭请求
78+
//rxjava2
79+
implementation 'io.reactivex.rxjava2:rxjava:2.2.8'
80+
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
81+
implementation 'com.ljx.rxlife2:rxlife-rxjava:2.0.0' //管理RxJava2生命周期,页面销毁,关闭请求
82+
83+
//rxjava3
84+
implementation 'io.reactivex.rxjava3:rxjava:3.0.2'
85+
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
86+
implementation 'com.ljx.rxlife3:rxlife-rxjava:3.0.0' //管理RxJava3生命周期,页面销毁,关闭请求
87+
88+
//Converter 根据自己需求选择 RxHttp默认内置了GsonConverter
89+
implementation 'com.ljx.rxhttp:converter-jackson:2.2.5'
90+
implementation 'com.ljx.rxhttp:converter-fastjson:2.2.5'
91+
implementation 'com.ljx.rxhttp:converter-protobuf:2.2.5'
92+
implementation 'com.ljx.rxhttp:converter-simplexml:2.2.5'
11193
}
11294
```
11395

114-
最后,***rebuild一下(此步骤是必须的)*** ,就会自动生成RxHttp类,到这,准备工作完毕。
115-
116-
11796
# 上手教程
11897

11998
30秒上手教程:https://juejin.im/post/5cfcbbcbe51d455a694f94df

0 commit comments

Comments
 (0)