gradle依赖
//使用kapt依赖rxhttp-compiler,需要导入kapt插件
apply plugin: ‘kotlin-kapt’
android {
defaultConfig {
javaCompileOptions {
annotationProcessorOptions {
arguments = [
//必须,告知RxHttp你依赖的okhttp版本,目前已适配 v3.12.0 - v4.9.0版本 (v4.3.0除外)
rxhttp_okhttp: ‘4.9.0’,
//使用asXxx方法时必须,告知RxHttp你依赖的rxjava版本,可传入rxjava2、rxjava3
rxhttp_rxjava: ‘rxjava3’,
rxhttp_package: ‘rxhttp’ //非必须,指定RxHttp类包名
]
}
}
}
//必须,java 8或更高
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
//以下3个为必须,
implementation ‘com.ljx.rxhttp:rxhttp:2.4.1’
implementation ‘com.squareup.okhttp3:okhttp:4.9.0’ //rxhttp v2.2.2版本起,需要手动依赖okhttp
kapt ‘com.ljx.rxhttp:rxhttp-compiler:2.4.1’ //生成RxHttp类,纯Java项目,请使用annotationProcessor代替kapt
implementation ‘com.ljx.rxlife:rxlife-coroutine:2.0.1’ //管理协程生命周期,页面销毁,关闭请求
//rxjava2 (RxJava2/Rxjava3二选一,使用asXxx方法时必须)
implementation ‘io.reactivex.rxjava2:rxjava:2.2.8’
implementation ‘io.reactivex.rxjava2:rxandroid:2.1.1’
implementation ‘com.ljx.rxlife2:rxlife-rxjava:2.0.0’ //管理RxJava2生命周期,页面销毁,关闭请求
//rxjava3
implementation ‘io.reactivex.rxjava3:rxjava:3.0.6’
implementation ‘io.reactivex.rxjava3:rxandroid:3.0.0’
implementation ‘com.ljx.rxlife3:rxlife-rxjava:3.0.0’ //管理RxJava3生命周期,页面销毁,关闭请求
//非必须,根据自己需求选择 RxHttp默认内置了GsonConverter
implementation ‘com.ljx.rxhttp:converter-fastjson:2.4.1’
implementation ‘com.ljx.rxhttp:converter-jackson:2.4.1’
implementation ‘com.ljx.rxhttp:converter-moshi:2.4.1’
implementation ‘com.ljx.rxhttp:converter-protobuf:2.4.1’
implementation ‘com.ljx.rxhttp:converter-simplexml:2.4.1’
}
复制代码
2、Android 10/11 分区存储
当我们App的targetSdkVersion
更改为28以上,并且运行在Android 10以上设备时,我们无法再以绝对路径的方式,去读写非沙盒目录下的文件,当然,如果App是覆盖安装(如:targetSdkVersion 28 覆盖安装为 29),则会保持原来的访问方式。
requestLegacyExternalStorage属性
如果我们的app将targetSdkVersion更改为28以上,且想保持原来的访问方式,则需要在清单文件中将 requestLegacyExternalStorage
的值设置为 true
,如下:
<manifest …>
<application android:requestLegacyExternalStorage=“true” … >
…
复制代码
此时,便可继续以原来的方式去读写文件,然而,在Android 11上,Google又给了它新的含义,来看看官网的原话
也就是说,在Android 11设备上ÿ