Android编译报错:找不到android:attr/lStar资源,升级core库无效
解决Android编译AAPT错误:resource android:attr/lStar not found
问题背景
编译Android项目时出现AAPT错误,提示resource android:attr/lStar not found,项目配置如下:
android { compileSdkVersion 33 buildToolsVersion '33.0.1' defaultConfig { minSdkVersion 23 targetSdkVersion 33 multiDexEnabled true } dependencies { implementation "androidx.activity:activity:1.2.4" implementation "androidx.constraintlayout:constraintlayout:1.1.3" implementation "androidx.core:core:1.8.0" ... } ... }
错误日志片段:
/Users/project_xxx/.gradle/caches/transforms-2/files-2.1/253e1f848d23fb0aa7dda4fdaafb503b/core-1.8.0/res/values/values.xml:104:5-113:25: AAPT: error: resource
尝试升级androidx.core:core到1.8.0、1.9.0,以及执行clean、rebuild、Invalidate caches and Restart操作后问题仍存在。
解决方案
1. 强制统一androidx.core依赖版本
项目中可能存在其他依赖间接引入了不兼容的androidx.core版本,导致属性冲突。在根目录的build.gradle中添加依赖约束,强制所有模块使用指定版本:
allprojects { configurations.all { resolutionStrategy { force 'androidx.core:core:1.8.0' // 或你使用的1.9.0版本 } } }
2. 升级老旧依赖到适配API 33的版本
当前使用的androidx.activity:activity:1.2.4和androidx.constraintlayout:constraintlayout:1.1.3版本较旧,未适配API 33的新增属性,建议升级:
dependencies { implementation "androidx.activity:activity:1.6.1" implementation "androidx.constraintlayout:constraintlayout:2.1.4" implementation "androidx.core:core:1.8.0" // 其他依赖保持或按需升级 }
3. 清理Gradle缓存
手动删除Gradle缓存目录,彻底清理旧的编译文件:
- 找到缓存路径:
/Users/project_xxx/.gradle/caches/transforms-2 - 删除该目录下的所有内容,然后重新同步项目并编译
4. 检查第三方依赖的兼容性
部分第三方库可能仍使用旧的Android Support库而非AndroidX,导致属性冲突。执行以下命令查看依赖树:
./gradlew app:dependencies
找出使用Support库的依赖,要么升级该库到支持AndroidX的版本,要么在gradle.properties中开启Jetifier兼容:
android.useAndroidX=true android.enableJetifier=true
内容的提问来源于stack exchange,提问作者Joanne Chang
相关产品推荐
相关产品推荐

