ERROR:: AAPT: error: resource style/Widget.AppCompat.TextView not found. 原因及解决

把android项目从support-v4升级到androidx之后,出现错误
ERROR:: AAPT: error: resource style/Widget.AppCompat.TextView (aka com.example:style/Widget.AppCompat.TextView) not found.
 

一头雾水,在网上搜索,有人说是子项目和主项目版本不匹配,使用如下方式统一,统一之后,发现还是不行。
 

 

除此也搜索不到什么有用的东西,根据经验,找不到答案,要么是问题太偏,要么是问题太简单。
我想多是后者吧,问不出所以然,那就只能自力更生。


既然没有,要不自己定义一下,使用\Android_Sdk\platforms\android-28\data\res\values\styles.xml中style做基类。
 

    <style name="Widget.AppCompat" parent="@android:style/Widget"/>
    <style name="Widget.AppCompat.TextView" parent="@android:style/Widget.TextView"/>

不过添加之后又有其他错误,类似
AGPBI: {"kind":"error","text":"Android resource linking failed","sources":[{"file":"C:\\Users\\lgs\\.gradle\\caches\\transforms-3\\fdf8d8302d80daaa032d669a233a0150\\transformed\\material-1.4.0\\res\\layout\\mtrl_alert_select_dialog_multichoice.xml","position":{"startLine":44}}],"original":"ERROR:C:\\Users\\lgs\\.gradle\\caches\\transforms-3\\fdf8d8302d80daaa032d669a233a0150\\transformed\\material-1.4.0\\res\\layout\\mtrl_alert_select_dialog_multichoice.xml:45: AAPT: error: attribute drawableLeftCompat (aka com.example:drawableLeftCompat) not found.\n    ","tool":"AAPT"}
 

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@android:id/text1"
。。。
    app:drawableLeftCompat="?android:attr/listChoiceIndicatorMultiple" //资源找不到
    app:drawableStartCompat="?android:attr/listChoiceIndicatorMultiple"
    android:drawablePadding="20dp"
    android:ellipsize="marquee" />

发现许多相关资源也找不到。

Widget.AppCompat.TextView到底在哪里?
在新Androidx项目中Widget.AppCompat.TextView明明在\appcompat-1.3.1\res\values\values.xml被定义,为何找不到呢?
 

<style name="TextView1"  parent="Widget.AppCompat.TextView"/>

在当前项目中Widget.AppCompat.TextView不但找不到,连Widget.AppCompat都找不到,

而传统项目中使用的基类是android.widget.TextView,问题真的可能发生在appcompat的引用上。


仔细查看项目,真的有子模块使用了support-v4:28.0.0。大致可以猜测android-28和appcompat冲突了。

原来是所有子模块的support-v4:28.0.0都要替换为appcompat:1.3.1

 其他兼容问题做下简单的处理就可以了。

关于:

编者:李国帅

qq:9611153 微信lgs9611153

时间:2021-11-6  

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

微澜-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值