【Android】项目升级时报错 android:style/Holo.Widget

错误原因

当你创建一个新项目,然后使用一下新版本的依赖库,此时将老项目里面的代码迁移过来,或者直接在老版本项目里面升级依赖库的时候,有时候会碰见这样的错误提示。

java 复制代码
AGPBI: {"kind":"error","text":"Android resource linking failed","sources":[{}],"original":"AAPT: error: resource android:style/android:Widget.Holo.Light.ActionButton.CloseMode not found.\nerror: resource android:style/android:Widget not found.\nerror: resource android:style/android:TextAppearance.Holo.Widget.ActionBar.Menu not found.\nerror: failed linking references.\n\n    ","tool":"AAPT"}

AAPT: error: resource android:style/android:Widget.Holo.Light.ActionButton.CloseMode not found.
error: resource android:style/android:Widget not found.
error: resource android:style/android:TextAppearance.Holo.Widget.ActionBar.Menu not found.
error: failed linking references.
错误分析

这个错误信息表明,在构建 Android 项目时,AAPT(Android Asset Packaging Tool)无法找到某些 Android 样式(style)资源,具体来说是以下样式:

android:style/android:Widget.Holo.Light.ActionButton.CloseMode

android:style/android:Widget

android:style/android:TextAppearance.Holo.Widget.ActionBar.Menu

这个问题通常是由于以下几种原因引起的:

1.使用了不兼容的 Android 样式资源:

这些样式是 Holo 样式的一部分,而 Holo 风格是 Android 4.0(API 级别 14)之前的默认样式。在较高版本的 Android(API 级别 21 及以上)中,这些样式可能已被移除或不再支持。

2.项目中的目标 SDK 版本过高:

如果项目的 targetSdkVersion 设置得比较高(例如 21 或更高),并且应用代码或第三方库还在使用 Holo 样式,可能会导致这个错误。

3.依赖库使用了过时的资源:

如果使用的某些第三方库(例如,joygnssbase 或其他库)在某些地方使用了这些过时的样式资源,它们在高版本的 Android 系统上可能找不到。

错误解决

首先看项目依赖,是否还是依赖老式样式库,要是还想使用老式依赖库的话,就要降低目标sdk版本。

如果不想依赖老式样式库的话,比如使用新的样式风格

java 复制代码
implementation 'androidx.appcompat:appcompat:1.2.0' // AppCompat 库
implementation 'com.google.android.material:material:1.4.0' //  Material Design 库

此时就全局查找Holo 吧

ctrl +alt +F 进行全局查找

例如,在 styles.xml 中可能会看到类似的内容:

java 复制代码
<style name="AppTheme" parent="android:Theme.Holo.Light">
    <!-- 自定义样式 -->
</style>

如果有类似的条目,尝试将其更改为使用现代的样式(如 Material Components 或 AppCompat 样式)。

等到把所有的Holo替换为新的样式之后,再重新构建项目就好了。

相关推荐
從南走到北36 分钟前
JAVA国际版二手车交易二手车市场系统源码支持Android+IOS+H5+APP
android·java·ios
江上清风山间明月42 分钟前
Android 系统中进程和线程的区别
android·python·线程·进程
2501_940094022 小时前
mig烧录卡资源 Mig-Switch游戏合集 烧录卡 1.75T
android·游戏·安卓·switch
渡我白衣2 小时前
深入理解 OverlayFS:用分层的方式重新组织 Linux 文件系统
android·java·linux·运维·服务器·开发语言·人工智能
李浩洋932 小时前
Typora picgo-core gitee图片上传设置
gitee·typora·图片上传
2501_915106322 小时前
iOS性能调优的系统化实践,从架构分层到多工具协同的全流程优化指南(开发者深度版)
android·ios·小程序·架构·uni-app·iphone·webview
stevenzqzq3 小时前
android recyclerview缓存_缓存问题解决办法
android·java·缓存
下位子3 小时前
『OpenGL学习滤镜相机』- Day10: 相机预览与 OpenGL 结合
android·opengl
那就逆流而上吧3 小时前
Android AIDL 的详细讲解和实践指南
android
小叮当⇔4 小时前
Gitee完全新手教程
gitee