AAPT: error: resource android:attr/colorError not found. 如何解决?
时间: 2023-08-24 07:27:27 浏览: 642
这个问题通常是由于 Android Support 库版本不兼容导致的。解决方法如下:
1. 在 app 模块的 build.gradle 文件中,将 targetSdkVersion 与 compileSdkVersion 版本升级到最新的 Android 版本。
```
android {
compileSdkVersion 31
targetSdkVersion 31
...
}
```
2. 确保在 dependencies 中使用最新的 Support 库版本。可以在项目根目录下的 build.gradle 文件中设置全局的 Support 库版本:
```
ext {
supportLibVersion = "28.0.0"
}
subprojects {
...
dependencies {
...
implementation "com.android.support:appcompat-v7:$supportLibVersion"
implementation "com.android.support:design:$supportLibVersion"
...
}
}
```
然后在 app 模块的 build.gradle 文件中使用该全局变量:
```
dependencies {
...
implementation "com.android.support:appcompat-v7:$supportLibVersion"
implementation "com.android.support:design:$supportLibVersion"
...
}
```
3. 如果还是出现上述错误,可以尝试使用 AndroidX 库替换 Support 库。在 app 模块的 build.gradle 文件中添加以下代码:
```
android {
...
defaultConfig {
...
// 添加以下两行
useLibrary 'androidx.core'
javaCompileOptions { annotationProcessorOptions { includeCompileClasspath false } }
}
...
}
```
然后将 Support 库依赖替换为对应的 AndroidX 库依赖即可。例如:
```
dependencies {
...
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.5.0-alpha01'
...
}
```
以上是解决 AAPT 错误的一些方法,希望能够帮助到你。
阅读全文
相关推荐














