今天在Android Stuido重新编译项目,结果发现居然build failed!报的错如下:
Error:In <declare-styleable> FontFamilyFont, unable to find attribute android:font
Error:In <declare-styleable> FontFamilyFont, unable to find attribute android:ttcIndex
Error:In <declare-styleable> FontFamilyFont, unable to find attribute android:fontVariationSettings
Error:Execution failed for task ':ehframelibrary:processDebugResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt
这是什么情况啊!!!
那就问一下万能的大神吧,有说是:compileSdkVersion 和buildToolsVersion 的版本太低了,把这两个的版本改成最新的。关键是,我的这个项目都维护了将近一年了,怎么会突然出现这种情况呢?
我的项目中的compileSdkVersion和buildToolsVersion版本分别是:
compileSdkVersion 25
buildToolsVersion '25.0.2'
在没有什么思路的情况下,就先把compileSdkVersion 和buildToolsVersion提升到27和“27.0.3”吧(根据一篇参考博文进行设置),结果还是不行,还是报下面的错误:
Error:In <declare-styleable> FontFamilyFont, unable to find attribute android:fontVariationSettings
看来还是没有解决问题。
找到原因
直到后面看到这篇文章,我才明白我的情况是怎么回事。
这篇文章分析的思路,及解决的办法给我很大的参考。
产生上面一系列Error的原因是项目中support-v4有重复。
检查自己依赖的第三方库,都已经指定了support-v4包的版本号:25.1.1。然后检查Android Stuido的External Libraries列表中发现support-v4包居然有28.0.0-alphal1。至此,终于明白是第三方库的依赖引进的。
查看库依赖
在Android Stuido中切换到Terminal中输入:
gradle :app:dependencies --configuration compile
如果输入上面的命令报错的话,请参考下面的文章:
Android studio 如何查看 library 间的依赖关系
gradle环境变量配置
最终发现是WheelPicker这个三方库依赖了support-v4:latest.release,由此导致了上面Error的产生。
解决办法
剔除三方库中的support-v4包:
compile('cn.qqtheme.framework:WheelPicker:1.4.2') { exclude group: 'com.android.support' }
至此世界终于清静了。。。