android studio编译出错:Android resource linking failed

问题描述

今天在Android studio通过模拟器运行app的时候,出现了以下错误:

在这里插入图片描述

Android resource linking failed
AAPT: D:\developer\androidproject\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
D:\developer\androidproject\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
D:\developer\androidproject\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2781: error: resource android:attr/fontVariationSettings not found.
D:\developer\androidproject\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2782: error: resource android:attr/ttcIndex not found.
D:\developer\androidproject\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3207: error: resource android:attr/textFontWeight not found.
error: failed linking references.

提示Android resource linking failed,error: failed linking references。

问题排查

这种情况一般是项目配置导致的,打开 File–> Project Structure,看到modules选项内容如下:

在这里插入图片描述
在上图中会发现compile sdk version 和build tools version版本不一致,将build tools version版本也改为26.
如下图所示:
在这里插入图片描述
再次运行成功。

有时候修改了上述配置后,还会遇到“Android resource linking failed”的错误,但是,仔细看构建信息,可能还会遇到另外一种错误,如下图标记所示:
在这里插入图片描述
错误内容是:

The specified Android SDK Build Tools version (26.0.0) is ignored, as it is below the minimum supported version (29.0.2) for Android Gradle Plugin 4.0.1.

这个就涉及到Android gradle插件了,具体的可参考官网,找到相匹配的版本。
在这里插入图片描述

网址是:
https://developer.android.google.cn/studio/releases/gradle-plugin?hl=zh_cn

猜你喜欢

转载自blog.csdn.net/u010261965/article/details/108414961