打包APK时遇android:attr/lStar资源缺失错误,模拟器运行正常
解决Android构建Release APK时
android:attr/lStar not found错误 构建Release APK时出现资源链接错误,提示
android:attr/lStar not found,但Debug模式下模拟器运行正常,错误信息如下:FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':cached_video_player:verifyReleaseResources'. > A failure occurred while executing com.android.build.gradle.tasks.VerifyLibraryResourcesTask$Action > Android resource linking failed ERROR:C:\Users\Mazen\.gradle\caches\transforms-3\e1db1d7e58d402c8040729c1f98d1141\transformed\core-1.7.0\res\values\values.xml:105:5-114:25: AAPT: error: resource android:attr/lStar not found. * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 27s Running Gradle task 'assembleRelease'... 28.4s Gradle task assembleRelease failed with exit code 1
问题根源
android:attr/lStar是Android 12(API级别31)新增的属性,你项目依赖的androidx.core:core-1.7.0库使用了该属性,但你的项目compileSdkVersion低于31。Release构建时会严格验证所有资源兼容性,而Debug模式下部分验证被跳过,因此模拟器运行正常但Release构建失败。
解决方法
方案1:升级项目Compile SDK版本
打开模块级build.gradle(通常是app/build.gradle),将compileSdkVersion和targetSdkVersion升级到31或更高版本:android { compileSdkVersion 33 defaultConfig { applicationId "com.your.package.name" minSdkVersion 21 // 根据你的需求保留或调整 targetSdkVersion 33 versionCode 1 versionName "1.0" } }方案2:强制降级冲突的Core库版本
若暂时无法升级Compile SDK,可在模块级build.gradle中添加依赖约束,强制使用不依赖API 31属性的core库版本:dependencies { constraints { implementation("androidx.core:core:1.6.0") { because "core:1.7.0及以上版本要求compileSdkVersion至少为31" } } // 其他依赖... }方案3:更新第三方依赖库
错误提示中涉及的cached_video_player库可能间接引入了高版本的core库,可查看该库的官方文档,更新到适配你当前Compile SDK版本的最新版,或确认其支持的最低Compile SDK要求。
内容的提问来源于stack exchange,提问作者Mazen Elkorashy
相关产品推荐
相关产品推荐

