美文网首页
使用Androidx的项目依赖使用support包的三方库为什么

使用Androidx的项目依赖使用support包的三方库为什么

作者: 拙峰朽木 | 来源:发表于2020-05-20 10:28 被阅读0次

之前在使用support包的android项目中引用了使用androidx的三方库,会报异常。比如下面的glide。

dependencies {
    implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')
    implementation 'com.github.bumptech.glide:glide:4.10.0'
    implementation deps.support.recyclerview_v7
    implementation deps.support.appcompat_v7
}

其中glide在4.10.0开始使用了androidx。编译这个项目会报异常:

image

解决方式:要么是项目升级使用Androidx,要么降低glide版本为4.10.0以下版本。

为什么要说这个呢?
因为有了上面的经验我就以为:使用了Androidx的项目再依赖使用support包的三方库也会不兼容其实并不会。
还是刚才的项目,只是将项目改为AndroidX的了,glide使用了4.8.0版本。

dependencies {
    implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
}

编译直接就过了。

我随机找了下4.8.0的glide些源码


image

可以看到,里面确实使用的是support的库。然后我将当前项目打成apk包,并反编译,看下最终glide使用的到底是support还是androidx的依赖。

image

看上面反编译的截图,ArrayMap这个已经被从android.support版本替换成adnroidx的了。

总结

当androidx的项目中依赖了使用基于support的三方库,在编译后系统会将他替换成对应的androidx的依赖。所以不会存在兼容问题。反之,如果基于support的项目依赖了基于androidx的三方库,怎编译会报不能兼容的错误。

如果谁知道这个替换的流程,希望可以跟我分享下。

相关文章

网友评论

      本文标题:使用Androidx的项目依赖使用support包的三方库为什么

      本文链接:https://www.haomeiwen.com/subject/zurgohtx.html