question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MdcTheme crashes when running a preview

See original GitHub issue

Running a preview on emulator that uses MdcTheme crashes with the following error:

Caused by: java.lang.IllegalArgumentException: MaterialThemeUsingMdcTheme requires the host context's theme to extend Theme.MaterialComponents
 at com.google.android.material.composethemeadapter.MdcTheme.createMdcTheme(MdcTheme.kt:134)
 at com.google.android.material.composethemeadapter.MdcTheme.createMdcTheme$default(MdcTheme.kt:125)
 at com.google.android.material.composethemeadapter.MdcTheme.MdcTheme(MdcTheme.kt:75)

How to reproduce

Open the MigrationCodelab project from the android-compose-codelabs end branch and run any of the previews in the PlantDetailDescription.kt file.

Versions

  • Compose alpha06
  • Android Studio 4.2 Canary 13

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
davidvavracommented, Dec 8, 2021

This is more Android Studio issue than issue of this library. I created an issue in Android Studio tracker: https://issuetracker.google.com/issues/209652365

0reactions
ChrisTitoscommented, Nov 29, 2021

When I try to open the sample project of this repo I get the same error. (I don’t get it in my personal project). When I added a new file with a Preview in it, it previewed correctly once, but after editing/refreshing I keep getting this error again.

Android Studio Arctic Fox | 2020.3.1 Patch 3

This was the preview I tried to add in a new file:

@Preview
@Composable
fun TypoPreview() {
    Column {
        Text(text = "Hello world", style = MaterialTheme.typography.h3)
        MdcTheme {
            Text(text = "Hello world", style = MaterialTheme.typography.h3)
        }
    }
}

(I was trying to see if the fonts of the theme should work, because that’s not working in preview in my project)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Preview Crashes when using @FetchRequest
I'm trying to load items from the database into a list, it works fine on device and simulator but Preview will always crash...
Read more >
Integrating Compose with your existing UI - Android Developers
This tightly couples those View elements together: The custom View may crash or be broken if it can't find the child, and the...
Read more >
Converting an existing app screen to Jetpack Compose (Part 1)
Jetpack Compose is now in alpha. In this livestream, we'll go through migrating an existing app screen from using Views and MDC-Android to ......
Read more >
Enable theme in jetpack compose preview : r/androiddev
I'm using MdcTheme to integrate existing theme in compose and it working when I built and run on device, but it's not working...
Read more >
Jetpack compose preview crashes with hiltViewModel<>()
After some searching and reviewing of google sample codes here is the way you must follow to prevent the preview crashes:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found