【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替换为新的样式之后,再重新构建项目就好了。

相关推荐
7177771 天前
2026 国产 Jira 替代方案排名:技术决策者选型指南与 Gitee 定位分析
gitee·jira
booboosui1 天前
Android 上的无人回合:只放开 2 类工具,宁可空手
android
透明的玻璃杯1 天前
gitee使用方法
gitee
事圆则缓1 天前
Android 性能排查实战:怎么看内存抖动、CPU 占用和 FPS
android
mmsx1 天前
Android 三类「看着无关」的故障:大事务、UI 阻塞与 ViewModel 作用域
android·ui
换元不配限1 天前
Android 休眠与唤醒完全指南:从手机到 IoT 设备的实战解析
android·物联网·智能手机·alarmmanager·wakelock·workmanager·休眠和唤醒
通信侠1 天前
android 16触摸提示音Back虚拟按键无声
android
GY-931 天前
【Android 】App工程结构和配置
android
360智汇云1 天前
隔离VPC标准路径:出公网链路的设计与实现
android·服务器·数据库
nece0011 天前
win10家庭版安装Android模拟器(AVD 安卓虚拟设备)
android·模拟器