记录一个AndroidX和Android support库不能共存的坑

今天用到第三方库的时候一直报异常More than one file was found with OS independent path 'META-INF/androidx.legacy_legacy-support-core-utils.version'

谷歌了一下找到方法需要在app.gradle文件里面android节点下添加这样的代码

       packagingOptions {
            exclude 'META-INF/XXX'
           exclude 'META-INF/XXX'
           exclude 'META-INF/XXX'
            exclude 'META-INF/XXX'
        }

于是手动添加后同步,发现报相同的异常More than one file was found with OS independent path 'META-INF/androidx.loader_loader.version'

 

我想着也就两三个文件,于是保持耐心一个个添加,直到加到十几个的时候我崩溃了。

整理思路,一定有别的方法。

问题出现在我添加PhotoView的依赖之后,第三方库implementation 'com.github.chrisbanes:PhotoView:latest.release'引用了最新版本Androidx,而Androidx和Android support库不能共存

考虑到我的项目不依赖于AndroidX,我选择回退PhotoView依赖库的版本到2.1.4,问题完美解决。

https://www.jianshu.com/p/f7a7a8765294 该文章讲述的更加具体,给了我很大帮助。

猜你喜欢

转载自www.cnblogs.com/machach/p/10243528.html