Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] "Failed to inflate ColorStateList" error is logged when setting Color to CheckBox #18897

Closed
tranb3r opened this issue Nov 20, 2023 · 14 comments · Fixed by #24658
Closed
Labels
area-controls-checkbox CheckBox fixed-in-8.0.90 fixed-in-9.0.0-rc.2.24503.2 has-workaround p/2 Work that is important, but is currently not scheduled for release platform/android 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@tranb3r
Copy link

tranb3r commented Nov 20, 2023

Description

When setting Color to CheckBox on Android, the following error is logged, even if the functionality seems to work:

[ResourcesCompat] Failed to inflate ColorStateList, leaving it to the framework
[ResourcesCompat] java.lang.UnsupportedOperationException: Failed to resolve attribute at index 0: TypedValue{t=0x2/d=0x7f040111 a=-1}, theme={InheritanceMap=[id=0x7f120137com.ouibank.android.app:style/Maui.MainTheme.NoActionBar, id=0x7f120136com.ouibank.android.app:style/Maui.MainTheme, id=0x7f120249com.ouibank.android.app:style/Theme.MaterialComponents.DayNight, id=0x7f120262com.ouibank.android.app:style/Theme.MaterialComponents.Light, id=0x7f12006bcom.ouibank.android.app:style/Base.Theme.MaterialComponents.Light, id=0x7f1200a4com.ouibank.android.app:style/Base.V21.Theme.MaterialComponents.Light, id=0x7f120092com.ouibank.android.app:style/Base.V14.Theme.MaterialComponents.Light, id=0x7f120093com.ouibank.android.app:style/Base.V14.Theme.MaterialComponents.Light.Bridge, id=0x7f120140com.ouibank.android.app:style/Platform.MaterialComponents.Light, id=0x7f12021ccom.ouibank.android.app:style/Theme.AppCompat.Light, id=0x7f120053com.ouibank.android.app:style/Base.Theme.AppCompat.Light, id=0x7f1200b6com.ouibank.android.app:style/Base.V28.Theme.AppCompat.Light, id=0x7f1200b3com.ouibank.android.app:style/Base.V26.Theme.AppCompat.Light, id=0x7f1200adcom.ouibank.android.app:style/Base.V23.Theme.AppCompat.Light, id=0x7f1200abcom.ouibank.android.app:style/Base.V22.Theme.AppCompat.Light, id=0x7f1200a0com.ouibank.android.app:style/Base.V21.Theme.AppCompat.Light, id=0x7f1200b9com.ouibank.android.app:style/Base.V7.Theme.AppCompat.Light, id=0x7f12013dcom.ouibank.android.app:style/Platform.AppCompat.Light, id=0x7f120148com.ouibank.android.app:style/Platform.V25.AppCompat.Light, id=0x1030241android:style/Theme.Material.Light.NoActionBar, id=0x1030237android:style/Theme.Material.Light, id=0x103000candroid:style/Theme.Light, id=0x1030005android:style/Theme], Themes=[com.ouibank.android.app:style/Maui.MainTheme.NoActionBar, forced, com.ouibank.android.app:style/Maui.SplashTheme, forced, com.ouibank.android.app:style/Theme.AppCompat.Empty, forced, android:style/Theme.DeviceDefault.Light.DarkActionBar, forced]}
[ResourcesCompat] 	at android.content.res.TypedArray.getColor(TypedArray.java:529)
[ResourcesCompat] 	at androidx.core.content.res.ColorStateListInflaterCompat.inflate(ColorStateListInflaterCompat.java:159)
[ResourcesCompat] 	at androidx.core.content.res.ColorStateListInflaterCompat.createFromXmlInner(ColorStateListInflaterCompat.java:124)
[ResourcesCompat] 	at androidx.core.content.res.ColorStateListInflaterCompat.createFromXml(ColorStateListInflaterCompat.java:103)
[ResourcesCompat] 	at androidx.core.content.res.ResourcesCompat.inflateColorStateList(ResourcesCompat.java:262)
[ResourcesCompat] 	at androidx.core.content.res.ResourcesCompat.getColorStateList(ResourcesCompat.java:236)
[ResourcesCompat] 	at androidx.core.content.ContextCompat.getColorStateList(ContextCompat.java:562)
[ResourcesCompat] 	at androidx.appcompat.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:48)
[ResourcesCompat] 	at androidx.appcompat.widget.TintTypedArray.getColorStateList(TintTypedArray.java:179)
[ResourcesCompat] 	at androidx.appcompat.widget.AppCompatCompoundButtonHelper.loadFromAttributes(AppCompatCompoundButtonHelper.java:81)
[ResourcesCompat] 	at androidx.appcompat.widget.AppCompatCheckBox.<init>(AppCompatCheckBox.java:84)
[ResourcesCompat] 	at com.google.android.material.checkbox.MaterialCheckBox.<init>(MaterialCheckBox.java:231)
[ResourcesCompat] 	at com.google.android.material.checkbox.MaterialCheckBox.<init>(MaterialCheckBox.java:227)
[ResourcesCompat] 	at com.google.android.material.checkbox.MaterialCheckBox.<init>(MaterialCheckBox.java:223)
[ResourcesCompat] 	at crc6452ffdc5b34af3a0f.NavigationViewFragment.n_onCreateView(Native Method)
[ResourcesCompat] 	at crc6452ffdc5b34af3a0f.NavigationViewFragment.onCreateView(NavigationViewFragment.java:42)
[ResourcesCompat] 	at androidx.fragment.app.Fragment.performCreateView(Fragment.java:3114)
[ResourcesCompat] 	at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:557)
[ResourcesCompat] 	at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:272)
[ResourcesCompat] 	at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1943)
[ResourcesCompat] 	at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1845)
[ResourcesCompat] 	at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1782)
[ResourcesCompat] 	at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:565)
[ResourcesCompat] 	at android.os.Handler.handleCallback(Handler.java:958)
[ResourcesCompat] 	at android.os.Handler.dispatchMessage(Handler.java:99)
[ResourcesCompat] 	at android.os.Looper.loopOnce(Looper.java:205)
[ResourcesCompat] 	at android.os.Looper.loop(Looper.java:294)
[ResourcesCompat] 	at android.app.ActivityThread.main(ActivityThread.java:8177)
[ResourcesCompat] 	at java.lang.reflect.Method.invoke(Native Method)
[ResourcesCompat] 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
[ResourcesCompat] 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

Is this hidding some kind of bug? Is it possible to avoid this log?

Steps to Reproduce

  1. Open repro project
  2. Click on "Checkbox test" button ; it navigates to a new page with a simple colored checkbox
  3. Observe output window in visual studio: an error is logged.

Link to public reproduction project repository

https://github.com/tranb3r/Issues/tree/main/MauiAppMaterialButtonAndCheckbox

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 14

Did you find any workaround?

No response

Relevant log output

No response

@tranb3r tranb3r added the t/bug Something isn't working label Nov 20, 2023
@ghost ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Nov 20, 2023
@jsuarezruiz jsuarezruiz added this to the Backlog milestone Nov 20, 2023
@ghost
Copy link

ghost commented Nov 20, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@BaltoAF
Copy link

BaltoAF commented Dec 1, 2023

Exact same problem here with Android 13 and MAUI 8.0.3

@AnnYang01
Copy link

Verified this on Visual Studio Enterprise 17.9.0 Preview 2 (.Net8.0). Repro on Android 14.0-API34 with below project.
MauiApp1.zip
image

@AnnYang01 AnnYang01 added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Dec 22, 2023
@cworth33
Copy link

cworth33 commented Jan 2, 2024

I'm getting this error too. Our page is similar to a survey where it is defined by a admin who lays out the questions and answers. If you get enough of the checkboxes on the UI the app hangs/crashes.

@mrwatts
Copy link

mrwatts commented Jan 6, 2024

According to my tests, this error doesn't even need the color to be set to occur. Steps to reproduce:

  1. Create a new Maui project using the template
  2. Remove the Checkbox styling from Styles.xaml (to prove the point)
  3. Add <Checkbox/> to MainPage.xaml
  4. Run app in debug mode in Android emulator
  5. Observe the error

@Larhei
Copy link

Larhei commented Jan 20, 2024

Workaround working for me to stop the exception:

  1. Download Colorstates of checkbox from material-components
  2. Change android:color="@xxxx" to android:color="#FFFFFF"
    The color does not matter.
  3. Add a new Folder color to Platforms/Android/Resources
  4. Add the two xml files with Build Action "AndroidResource"

@last-Programmer
Copy link

@Larhei i tried and i get the error invalid file path. API2144 for this files during the build

@Larhei
Copy link

Larhei commented Jan 20, 2024

In my cspro
<ItemGroup> <None Remove="Platforms\Android\Resources\color\m3_checkbox_button_icon_tint.xml" /> <None Remove="Platforms\Android\Resources\color\m3_checkbox_button_tint.xml" /> </ItemGroup>

Worked for me with maui 8.0.6 and vs 17.8.4 and dont forget to clean your bin/xxx/Android folder ;-)

@last-Programmer
Copy link

@Larhei thanks

Add a new Folder colors to Platforms/Android/Resources

i created the colors folder instead of color. all good now. i am not getting the exception now. thanks a lot for the heads up.

@maonaoda
Copy link
Contributor

maonaoda commented Feb 5, 2024

This hasn't been fixed yet...

@mrwatts
Copy link

mrwatts commented Feb 9, 2024

Workaround working for me to stop the exception:

  1. Download Colorstates of checkbox from material-components
  2. Change android:color="@xxxx" to android:color="#FFFFFF"
    The color does not matter.
  3. Add a new Folder color to Platforms/Android/Resources
  4. Add the two xml files with Build Action "AndroidResource"

Thanks for this. Worked like a charm. I didn't need to add lines to my .csproj file. Just adding the files to Platforms/Android/Resources/color and settings the items to android:color="#FFFFFF" was enough. I didn't set the build action to AndroidResource either. That isn't available. Running VS 17.8.5 and Maui 8.0.6.

gavin-orsetti added a commit to gavin-orsetti/FleetPlanner that referenced this issue Feb 23, 2024
…e I want to continue with the full refactor since the views have started to exhibit some very strange bugs that are a little bit trickier to track down than I would like.

Also implemented a work around described here dotnet/maui#18897
for the checkbox error that was being logged.
kimgoetzke added a commit to kimgoetzke/listem that referenced this issue Mar 28, 2024
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
@samhouts samhouts added p/2 Work that is important, but is currently not scheduled for release has-workaround labels Jun 18, 2024
@bradyguyc
Copy link

This work around is still required in 9.0.100-preview.5.24307.3 visualstudio 17.11.0 preview 2.1

@PureWeen PureWeen moved this from Todo to Ready To Review in MAUI SDK Ongoing Sep 8, 2024
@github-project-automation github-project-automation bot moved this from Ready To Review to Done in MAUI SDK Ongoing Sep 9, 2024
@OnClickListener2048
Copy link

worked like a charm!

@MsShiftDev
Copy link

Larhei

Shoutout to Larhei! I hope someone gives him/her/them a cookie! I did not need step 4, but the first three resolved the issue for me.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-checkbox CheckBox fixed-in-8.0.90 fixed-in-9.0.0-rc.2.24503.2 has-workaround p/2 Work that is important, but is currently not scheduled for release platform/android 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.