Closed stkent closed 8 months ago
Hi @stkent, does the issue happen on a real device running the latest production version of Android U? I wonder if that emulator image is outdated.
Hi @dsn5ft, thank you for the quick response! I tested on my personal Pixel 8 Pro running the December update of Android 34, and found that the crash still occurred there. I am currently installing the latest available system update and will report back once I've tested there too.
Also, in case it is relevant, our app's base theme is Theme.MaterialComponents.DayNight.NoActionBar
, i.e. is not based on Material 3. In other locations I know we've had to add attribute values to our M2-based theme to support M3-based components; is it perhaps the case that a new attribute needs to be added to our M2 theme as a result of MDC library changes?
Ah, yes. If you are using ThemeOverlay.Material3.MaterialAlertDialog
then you must make sure you are using an M3 base theme (otherwise you have to add all attributes from the M3 theme to your theme to avoid attribute not found issues).
Closing the issue since that seems to definitely be what's going on, but feel free to keep the conversation going here.
OK, I think the M2 app theme is the issue here. In our dialog overlay style:
<style name="Redacted.Dialog.ThemeOverlay" parent="ThemeOverlay.Material3.MaterialAlertDialog">
<item name="buttonBarNegativeButtonStyle">@style/Redacted.Dialog.ButtonStyle.Secondary</item>
<item name="buttonBarNeutralButtonStyle">@style/Redacted.Dialog.ButtonStyle.Primary</item>
<item name="buttonBarPositiveButtonStyle">@style/Redacted.Dialog.ButtonStyle.Primary</item>
<item name="materialAlertDialogBodyTextStyle">@style/Redacted.Dialog.Body.Text</item>
<item name="materialAlertDialogTitleTextStyle">@style/Redacted.Dialog.Title.Text</item>
<item name="alertDialogStyle">@style/Redacted.Dialog.Style</item>
<item name="android:backgroundTint">@color/backgroundPrimaryElevated</item>
<item name="android:backgroundDimAmount">0.56</item>
</style>
I added a temporary backgroundTint
attribute to the Redacted.Dialog.Style
style:
<style name="Redacted.Dialog.Style" parent="MaterialAlertDialog.Material3">
<item name="shapeAppearance">@style/ShapeAppearance.Material3.Corner.ExtraLarge</item>
<item name="shapeAppearanceOverlay">@null</item>
+ <item name="backgroundTint">@android:color/transparent</item>
</style>
and the app no longer crashes. I think this issue can be safely closed, if you agree!
Jinx, thanks for the help here :)
Np and thanks for confirming!
Description:
Instantiating a
MaterialAlertDialogBuilder
crashes after updating from library version 1.10.0 to library version 1.11.0. I am able to reproduce this on an emulator running the system image with release nameUpsideDownCake
, API Level34
, ABIarm64-v8a
, TargetAndroid 14.0 (Google Play)
, revision12
.This is the crash:
Expected behavior:
No crash, as in library version 1.10.0.
Source code:
Invocation:
MaterialAlertDialogBuilder(context, 0)
Minimal sample app repro:
I have not attempted to reproduce outside of our primary project at this time.
Android API version: 34.
Material Library version: 1.11.0.
Device: Emulator, see details in description.
~To help us triage faster, please check to make sure you are using the latest version of the library.~ ✅
Possibly related: https://github.com/material-components/material-components-android/issues/3666, though that specifically mentions usage of a beta version of Android U, which I do not believe is the case for this issue.