We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
新建core module,并依赖RxHttp,如下
core module
plugins { id 'com.android.library' id 'kotlin-android' id 'kotlin-kapt' } dependencies { implementation "com.squareup.okhttp3:okhttp:4.9.1" implementation 'com.github.liujingxing.rxhttp:rxhttp:2.7.2' kapt 'com.github.liujingxing.rxhttp:rxhttp-compiler:2.7.2' }
接着新建Http类,如下:
Http
object Http { @DefaultDomain const val base_url = "https://www.wanandroid.com/" suspend fun test() { RxHttp.get("/article/list/0/json") .toFlow<String>() .catch { } .collect { } } }
此时,执行assembleRelease命令,将core module打包为core-release.aar,并将该aar放至app module(主module)的libs文件下并依赖,如下:
assembleRelease
core-release.aar
aar
app module
repositories { flatDir { dirs 'libs' } } dependencies { implementation(name: 'core-release', ext: 'aar') //因aar会丢失一些远程依赖库,故需要手动依赖 implementation "com.squareup.okhttp3:okhttp:4.9.1" implementation 'com.github.liujingxing.rxhttp:rxhttp:2.7.2' implementation 'com.google.code.gson:gson:2.8.7' implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0" }
app module的MainActivity调用Http.test()方法,如下:
MainActivity
Http.test()
class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val button: Button = findViewById(R.id.button) button.setOnClickListener { lifecycleScope.launch { Http.test() } } }
在Android 6.0的手机上运行并点击Button按钮,就崩溃,具体日志如下:
Android 6.0
Button
其它设备未发现此问题
The text was updated successfully, but these errors were encountered:
我这没有Android 6.0设备,但我通过执行assembleDebug命令,生成app-debug.apk,将其安装到Android 11的设备上复现了这个问题,必现的。
assembleDebug
app-debug.apk
Android 11
直接运行或通过assembleRelease命令,生成app-release.apk,并未发现此问题
app-release.apk
进过一番摸索,这并非是RxHttp的问题,只要core module里使用了任意第三方库的接口静态方法,都会有这个问题,巧的是,RxHttp.get方法内部刚好调用了Param.get方法,而Param是接口类,Param.get是该接口的静态方法,所以就出现了上面的问题;
RxHttp
RxHttp.get
Param.get
Param
初步猜测是拆包所引起的问题,因为我查看app-debug.apk后,没有在dex文件找到Param.get方法,而app-release.apk里的dex文件是能找到Param.get方法的,所以app-release.apk没有问题
dex
下个版本将Param接口类改为抽象类以兼容这种情况
另外,我还发现,通过以下方式依赖aar,该问题也可以得到解决
implementation files('libs/xxx.aar')
并删除以下代码
repositories { flatDir { dirs 'libs' } }
Sorry, something went wrong.
No branches or pull requests
新建
core module
,并依赖RxHttp,如下接着新建
Http
类,如下:此时,执行
assembleRelease
命令,将core module
打包为core-release.aar
,并将该aar
放至app module
(主module)的libs文件下并依赖,如下:app module
的MainActivity
调用Http.test()
方法,如下:在
Android 6.0
的手机上运行并点击Button
按钮,就崩溃,具体日志如下:其它设备未发现此问题
The text was updated successfully, but these errors were encountered: