alorma / Compose-Settings

Compose Multiplatform #Compose Settings library
https://alorma.github.io/Compose-Settings/
MIT License
456 stars 28 forks source link

Example app crashes on start #98

Closed pelmenstar1 closed 1 year ago

pelmenstar1 commented 1 year ago

The stack trace:

Process: com.alorma.compose.settings.example, PID: 16781
android.content.res.Resources$NotFoundException: Resource ID #0x1060028
    at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:216)
    at android.content.res.Resources.getColor(Resources.java:961)
    at androidx.compose.material3.ColorResourceHelper.getColor-WaAFU9c(DynamicTonalPalette.kt:186)
    at androidx.compose.material3.DynamicTonalPaletteKt.dynamicTonalPalette(DynamicTonalPalette.kt:41)
    at androidx.compose.material3.DynamicTonalPaletteKt.dynamicDarkColorScheme(DynamicTonalPalette.kt:155)
    at com.alorma.compose.settings.example.ui.theme.ThemeKt.ComposeSettingsTheme(Theme.kt:20)
    at com.alorma.compose.settings.example.ComposableSingletons$MainActivityKt$lambda-1$1.invoke(MainActivity.kt:41)
    at com.alorma.compose.settings.example.ComposableSingletons$MainActivityKt$lambda-1$1.invoke(MainActivity.kt:28)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
    at androidx.compose.ui.platform.ComposeView.Content(ComposeView.android.kt:404)
    at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:250)
    at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:249)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
    at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
    at androidx.compose.ui.platform.CompositionLocalsKt.ProvideCommonCompositionLocals(CompositionLocals.kt:177)
    at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:123)
    at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:122)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
    at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
    at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt.ProvideAndroidCompositionLocals(AndroidCompositionLocals.android.kt:114)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$3.invoke(Wrapper.android.kt:157)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$3.invoke(Wrapper.android.kt:156)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
    at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:156)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:140)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
    at androidx.compose.runtime.ActualJvm_jvmKt.invokeComposable(ActualJvm.jvm.kt:78)
    at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:3248)
    at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:3238)
    at androidx.compose.runtime.SnapshotStateKt__DerivedStateKt.observeDerivedStateRecalculations(DerivedState.kt:341)
    at androidx.compose.runtime.SnapshotStateKt.observeDerivedStateRecalculations(Unknown Source:1)
    at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:3238)
    at androidx.compose.runtime.ComposerImpl.composeContent$runtime_release(Composer.kt:3173)

Looks like something is wrong with resources

pelmenstar1 commented 1 year ago

I think I found the reason.

Here is how the theme is initialized: https://github.com/alorma/Compose-Settings/blob/84b08ed1455cf250e12735d2cab8db1c43588ec3/app/src/main/java/com/alorma/compose/settings/example/ui/theme/Theme.kt#L11-L33

The problem is it just checks whether dynamicThemePreference is true. But it doesn't check the API level even though both dynamicDarkColorScheme and dynamicLightColorScheme require API level 31. By default, dynamicThemePreference is true regardless of the API level.

I launched the app on API level 28, so that's why the problem emerged. If dynamicThemePreference is disabled manually, everything works fine.

I will create a fix soon.