ERROR:: AAPT: error: resource style/Widget.AppCompat.TextView not found.

created at 11-09-2021 views: 54

After upgrading the android project from support-v4 to androidx, an error occurred

ERROR:: AAPT: error: resource style/Widget.AppCompat.TextView (aka com.example:style/Widget.AppCompat.TextView) not found.

I was confused and searched on the Internet. Some people said that the version of the sub-project and the main project did not match. The following methods were used to unify. After unification, I found that it still didn't work.

code

Besides, I can’t search for anything useful. Based on experience, I can’t find the answer. Either the question is too biased or the question is too simple.
I think it's mostly the latter. If I can't ask why, then I can only do it on my own.

Since there is no, or define it yourself, use style in \Android_Sdk\platforms\android-28\data\res\values\styles.xml as the base class.

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

But there are other errors after adding, similar to:

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" />

Found that many related resources can not be found.

Where is Widget.AppCompat.TextView in the end?
In the new Androidx project, Widget.AppCompat.TextView is clearly defined in \appcompat-1.3.1\res\values\values.xml, why can't it be found?

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

Not only can’t find Widget.AppCompat.TextView in the current project, even Widget.AppCompat can’t be found.

While the base class used in traditional projects is android.widget.TextView, the problem may really happen to the appcompat reference.

Check the project carefully, there are really sub-modules that use support-v4:28.0.0. It can be guessed that android-28 conflicts with appcompat.

It turns out that support-v4:28.0.0 of all submodules must be replaced with appcompat:1.3.1

appcompat:1.3.1

Other compatibility issues can be handled simply.

created at:11-09-2021
edited at: 11-09-2021: