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

[Compose] Preview does not work with GlideImage #4977

Closed
arriolac opened this issue Dec 21, 2022 · 16 comments
Closed

[Compose] Preview does not work with GlideImage #4977

arriolac opened this issue Dec 21, 2022 · 16 comments

Comments

@arriolac
Copy link

Glide Version: 1.0.0-alpha.1

Integration libraries: compose

Device/Android Version: emulator

GlideImage does not work with composable previews. The following code:

@OptIn(ExperimentalGlideComposeApi::class)
@Preview
@Composable
fun GlideImage() {
    GlideImage(
        model = "",
        contentDescription = null,
        modifier = Modifier.size(50.dp),
    )
}

...triggers this stracktrace:

java.lang.IllegalStateException: You cannot call Glide.get() in registerComponents(), use the provided Glide instance instead
	at com.bumptech.glide.Glide.checkAndInitializeGlide(Glide.java:145)
	at com.bumptech.glide.Glide.get(Glide.java:131)
	at com.bumptech.glide.Glide.getRetriever(Glide.java:510)
	at com.bumptech.glide.Glide.with(Glide.java:537)
	at com.bumptech.glide.integration.compose.GlideImageKt.GlideImage(GlideImage.kt:79)
	at com.google.samples.apps.sunflower.compose.plantdetail.PlantDetailViewKt.GlideImage(PlantDetailView.kt:603)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at androidx.compose.ui.tooling.ComposableInvoker.invokeComposableMethod(ComposableInvoker.kt:155)
	at androidx.compose.ui.tooling.ComposableInvoker.invokeComposable(ComposableInvoker.kt:195)
	at androidx.compose.ui.tooling.ComposeViewAdapter$init$3$1$composable$1.invoke(ComposeViewAdapter.kt:711)
	at androidx.compose.ui.tooling.ComposeViewAdapter$init$3$1$composable$1.invoke(ComposeViewAdapter.kt:709)
	at androidx.compose.ui.tooling.ComposeViewAdapter$init$3$1.invoke(ComposeViewAdapter.kt:746)
	at androidx.compose.ui.tooling.ComposeViewAdapter$init$3$1.invoke(ComposeViewAdapter.kt:704)
	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.tooling.InspectableKt.Inspectable(Inspectable.kt:61)
	at androidx.compose.ui.tooling.ComposeViewAdapter$WrapPreview$1.invoke(ComposeViewAdapter.kt:651)
	at androidx.compose.ui.tooling.ComposeViewAdapter$WrapPreview$1.invoke(ComposeViewAdapter.kt:650)
	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.tooling.ComposeViewAdapter.WrapPreview(ComposeViewAdapter.kt:645)
	at androidx.compose.ui.tooling.ComposeViewAdapter.access$WrapPreview(ComposeViewAdapter.kt:135)
	at androidx.compose.ui.tooling.ComposeViewAdapter$init$3.invoke(ComposeViewAdapter.kt:704)
	at androidx.compose.ui.tooling.ComposeViewAdapter$init$3.invoke(ComposeViewAdapter.kt:701)
	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)
	at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:3238)
	at androidx.compose.runtime.ComposerImpl.composeContent$runtime_release(Composer.kt:3173)
	at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:587)
	at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:950)
	at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:519)
	at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:140)
	at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:131)
	at androidx.compose.ui.platform.AndroidComposeView.setOnViewTreeOwnersAvailable(AndroidComposeView.android.kt:1060)
	at androidx.compose.ui.platform.WrappedComposition.setContent(Wrapper.android.kt:131)
	at androidx.compose.ui.platform.WrappedComposition.onStateChanged(Wrapper.android.kt:182)
	at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:360)
	at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:202)
	at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:138)
	at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:131)
	at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.android.kt:1147)
	at android.view.View.dispatchAttachedToWindow(View.java:20753)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3490)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
	at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:58)
	at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:366)
	at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:436)
	at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:121)
	at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:717)
	at com.android.tools.idea.rendering.RenderTask.lambda$inflate$9(RenderTask.java:873)
	at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$3.run(RenderExecutor.kt:192)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)

You can also validate this in the Sunflower sample app which has a GlideImage in its UI hierarchy: https://github.com/android/sunflower/blob/main/app/src/main/java/com/google/samples/apps/sunflower/compose/plantdetail/PlantDetailView.kt#L553

@sjudd
Copy link
Collaborator

sjudd commented Dec 24, 2022

I can't trivially reproduce this error in Glide's HorizontalGalleryFragment:

  @OptIn(ExperimentalGlideComposeApi::class)
  @Preview
  @Composable
  fun GlideImage() {
    GlideImage(
      model = null,
      contentDescription = null,
      modifier = Modifier.size(500.dp),
    )
  }

Produces:

image

@sjudd
Copy link
Collaborator

sjudd commented Dec 24, 2022

In the sunflower app though, I see a slightly different error:

java.lang.NullPointerException
	at com.bumptech.glide.module.ManifestParser.parse(ManifestParser.java:38)
	at com.bumptech.glide.Glide.initializeGlide(Glide.java:218)
	at com.bumptech.glide.Glide.initializeGlide(Glide.java:206)
	at com.bumptech.glide.Glide.checkAndInitializeGlide(Glide.java:150)
	at com.bumptech.glide.Glide.get(Glide.java:131)
	at com.bumptech.glide.Glide.getRetriever(Glide.java:510)
	at com.bumptech.glide.Glide.with(Glide.java:537)
	at com.bumptech.glide.integration.compose.GlideImageKt.GlideImage(GlideImage.kt:79)
	at com.google.samples.apps.sunflower.compose.plantdetail.PlantDetailViewKt.PlantImage-vlEVYhg(PlantDetailView.kt:307)
	at com.google.samples.apps.sunflower.compose.plantdetail.PlantDetailViewKt.access$PlantImage-vlEVYhg(PlantDetailView.kt:1)
	at com.google.samples.apps.sunflower.compose.plantdetail.PlantDetailViewKt$PlantDetailsContent_iHT_50w$lambda$19$$inlined$ConstraintLayout$2.invoke(ConstraintLayout.kt:1527)
	at com.google.samples.apps.sunflower.compose.plantdetail.PlantDetailViewKt$PlantDetailsContent_iHT_50w$lambda$19$$inlined$ConstraintLayout$2.invoke(ConstraintLayout.kt:89)
	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.layout.LayoutKt.MultiMeasureLayout(Layout.kt:403)
	at com.google.samples.apps.sunflower.compose.plantdetail.PlantDetailViewKt.PlantDetailsContent-iHT-50w(PlantDetailView.kt:729)
	at com.google.samples.apps.sunflower.compose.plantdetail.PlantDetailViewKt.PlantDetails(PlantDetailView.kt:201)
	at com.google.samples.apps.sunflower.compose.plantdetail.ComposableSingletons$PlantDetailViewKt$lambda-6$1.invoke(PlantDetailView.kt:556)
	at com.google.samples.apps.sunflower.compose.plantdetail.ComposableSingletons$PlantDetailViewKt$lambda-6$1.invoke(PlantDetailView.kt:555)
	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.material.SurfaceKt$Surface$1.invoke(Surface.kt:134)
	at androidx.compose.material.SurfaceKt$Surface$1.invoke(Surface.kt:117)
	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.material.SurfaceKt.Surface-F-jzlyU(Surface.kt:114)
	at com.google.samples.apps.sunflower.compose.plantdetail.ComposableSingletons$PlantDetailViewKt$lambda-7$1.invoke(PlantDetailView.kt:555)
	at com.google.samples.apps.sunflower.compose.plantdetail.ComposableSingletons$PlantDetailViewKt$lambda-7$1.invoke(PlantDetailView.kt:554)
	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 com.google.accompanist.themeadapter.material.MdcTheme$MdcTheme$1.invoke(MdcTheme.kt:115)
	at com.google.accompanist.themeadapter.material.MdcTheme$MdcTheme$1.invoke(MdcTheme.kt:112)
	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.material.MaterialTheme_androidKt.PlatformMaterialTheme(MaterialTheme.android.kt:23)
	at androidx.compose.material.MaterialThemeKt$MaterialTheme$1$1.invoke(MaterialTheme.kt:82)
	at androidx.compose.material.MaterialThemeKt$MaterialTheme$1$1.invoke(MaterialTheme.kt:81)
	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.material.TextKt.ProvideTextStyle(Text.kt:265)
	at androidx.compose.material.MaterialThemeKt$MaterialTheme$1.invoke(MaterialTheme.kt:81)
	at androidx.compose.material.MaterialThemeKt$MaterialTheme$1.invoke(MaterialTheme.kt:80)
	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.material.MaterialThemeKt.MaterialTheme(MaterialTheme.kt:72)
	at com.google.accompanist.themeadapter.material.MdcTheme.MdcTheme(MdcTheme.kt:108)
	at com.google.samples.apps.sunflower.compose.plantdetail.PlantDetailViewKt.PlantDetailContentPreview(PlantDetailView.kt:554)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at androidx.compose.ui.tooling.ComposableInvoker.invokeComposableMethod(ComposableInvoker.kt:155)
	at androidx.compose.ui.tooling.ComposableInvoker.invokeComposable(ComposableInvoker.kt:195)
	at androidx.compose.ui.tooling.ComposeViewAdapter$init$3$1$composable$1.invoke(ComposeViewAdapter.kt:711)
	at androidx.compose.ui.tooling.ComposeViewAdapter$init$3$1$composable$1.invoke(ComposeViewAdapter.kt:709)
	at androidx.compose.ui.tooling.ComposeViewAdapter$init$3$1.invoke(ComposeViewAdapter.kt:746)
	at androidx.compose.ui.tooling.ComposeViewAdapter$init$3$1.invoke(ComposeViewAdapter.kt:704)
	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.tooling.InspectableKt.Inspectable(Inspectable.kt:61)
	at androidx.compose.ui.tooling.ComposeViewAdapter$WrapPreview$1.invoke(ComposeViewAdapter.kt:651)
	at androidx.compose.ui.tooling.ComposeViewAdapter$WrapPreview$1.invoke(ComposeViewAdapter.kt:650)
	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.tooling.ComposeViewAdapter.WrapPreview(ComposeViewAdapter.kt:645)
	at androidx.compose.ui.tooling.ComposeViewAdapter.access$WrapPreview(ComposeViewAdapter.kt:135)
	at androidx.compose.ui.tooling.ComposeViewAdapter$init$3.invoke(ComposeViewAdapter.kt:704)
	at androidx.compose.ui.tooling.ComposeViewAdapter$init$3.invoke(ComposeViewAdapter.kt:701)
	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)
	at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:3238)
	at androidx.compose.runtime.ComposerImpl.composeContent$runtime_release(Composer.kt:3173)
	at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:587)
	at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:950)
	at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:519)
	at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:140)
	at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:131)
	at androidx.compose.ui.platform.AndroidComposeView.setOnViewTreeOwnersAvailable(AndroidComposeView.android.kt:1060)
	at androidx.compose.ui.platform.WrappedComposition.setContent(Wrapper.android.kt:131)
	at androidx.compose.ui.platform.WrappedComposition.onStateChanged(Wrapper.android.kt:182)
	at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:360)
	at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:202)
	at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:138)
	at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:131)
	at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.android.kt:1147)
	at android.view.View.dispatchAttachedToWindow(View.java:20753)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3490)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
	at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:58)
	at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:366)
	at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:436)
	at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:121)
	at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:717)
	at com.android.tools.idea.rendering.RenderTask.lambda$inflate$9(RenderTask.java:873)
	at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$3.run(RenderExecutor.kt:192)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)

@sjudd
Copy link
Collaborator

sjudd commented Dec 24, 2022

I think the stack trace I posted is the correct error. There's a static variable that's set and rest but not using a try/finally. That could cause two attempts to initialize Glide concurrently to both throw but with different causes. Assuming the preview ever does this, it would explain why there are two different stack traces.

So there's two, or maybe three bugs:

  1. Glide should use try/finally here:

isInitializing = true;
initializeGlide(context, generatedAppGlideModule);
isInitializing = false;

  1. Glide should check if AppInfo is null from the package manager:

ApplicationInfo appInfo =
context
.getPackageManager()
.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
if (appInfo.metaData == null) {

  1. Maybe Compose's preview logic should provide valid AppInfo?

In the meantime, you can work around this by disabling legacy manifest parsing:

  1. Adding a dependency on Glide's annotation processor: https://bumptech.github.io/glide/doc/download-setup.html#configuring-glide--annotation-processors
  2. returning false from isManifestParsingEnabled:
@GlideModule class AppGlideModule() {
  fun isManifestParsingEnabled = false
}

@sjudd
Copy link
Collaborator

sjudd commented Dec 24, 2022

Yeah actually I think the root cause is actually point #3 above, PackageManager.getApplicationInfo is annotated with @NonNull and documented as never being null in the javadoc: https://developer.android.com/reference/android/content/pm/PackageManager#getApplicationInfo(java.lang.String,%20int).

Still worth fixing the initialization error in Glide though, that'll at least make the root cause more clear.

@sjudd
Copy link
Collaborator

sjudd commented Dec 24, 2022

Filed b/263613353 internally. I also wrote a workaround in Glide, but I'll avoid submitting it until we understand better how long a fix in the tooling will take.

@sjudd
Copy link
Collaborator

sjudd commented Dec 24, 2022

https://github.com/sjudd/glide/tree/manifest_parser_null_app_info is the workaround for null application info

sjudd added a commit to sjudd/glide that referenced this issue Dec 24, 2022
Previously any exception in the initialization process could be hidden
by one of these recursive checks. The first time the exception occured,
it would be thrown normally, but subsequent times the recursive check
would be thrown instead. This complicates debugging.

Now we always unset the isInitializing boolean using try/finally. While
this doesn't fix anything directly, it does make debugging easier when
some kind of initialization error occurs.

Helps with bumptech#4977
sjudd added a commit to sjudd/glide that referenced this issue Dec 29, 2022
Previously any exception in the initialization process could be hidden
by one of these recursive checks. The first time the exception occured,
it would be thrown normally, but subsequent times the recursive check
would be thrown instead. This complicates debugging.

Now we always unset the isInitializing boolean using try/finally. While
this doesn't fix anything directly, it does make debugging easier when
some kind of initialization error occurs.

Helps with bumptech#4977
@arriolac
Copy link
Author

arriolac commented Jan 5, 2023

Thanks so much for looking into this @sjudd! 🙏

@sjudd
Copy link
Collaborator

sjudd commented Feb 13, 2023

Looks like there's no movement on fixing the issue in ASWB, so I'll submit the workaround.

@sjudd
Copy link
Collaborator

sjudd commented Feb 24, 2023

0f9aea2

@sjudd sjudd closed this as completed Feb 24, 2023
@mattcollins107
Copy link

mattcollins107 commented May 5, 2023

I'm working with GlideImage 1.0.0-alpha.3 and Glide 4.15.1, which should have the above fix, but I still see that Compose Previews fail to render when using GlideImage. The stack trace looks to be in a similar place as one from above:

android.content.pm.PackageManager$NameNotFoundException: PackageManager features are not supported
at com.android.layoutlib.bridge.android.BridgePackageManager.getApplicationInfo(BridgePackageManager.java:179)
at com.bumptech.glide.module.ManifestParser.getOurApplicationInfo(ManifestParser.java:35)
at com.bumptech.glide.module.ManifestParser.parse(ManifestParser.java:45)
at com.bumptech.glide.Glide.initializeGlide(Glide.java:221)
at com.bumptech.glide.Glide.initializeGlide(Glide.java:209)
at com.bumptech.glide.Glide.checkAndInitializeGlide(Glide.java:151)
at com.bumptech.glide.Glide.get(Glide.java:131)
at com.bumptech.glide.Glide.getRetriever(Glide.java:513)
at com.bumptech.glide.Glide.with(Glide.java:540)
at com.bumptech.glide.integration.compose.GlideImageKt.GlideImage(GlideImage.kt:107)
...

Any thoughts on this new exception?

@dsilvera
Copy link

Hi,
I have the same error of @mattcollins107

@minwonki
Copy link

Hi.
me too. same error of @mattcollins107

@GuillemRoca
Copy link

GuillemRoca commented May 26, 2023

We are having the same issue as @mattcollins107.

Just FYI for us this only happens with AS Flamingo releases or newer. If you want to avoid this issue revert back to using AS EE.

FYI @sjudd

@oluwasegunilori
Copy link

Same error on Hedgehog

@lulumeya
Copy link

lulumeya commented Jun 2, 2023

Can we expect 0f9aea2 this commit should fix this issue?

@hamid97m
Copy link

We should downgrade our AS to use glide :) It's awful

sabiou added a commit to sabiou/sunflower that referenced this issue Jan 2, 2024
… composable.

The SunflowerImage() wrapper was introduced as a workaround for the issue bumptech/glide#4977, and now that the issue has been resolved, there is no need for this wrapper in the codebase.

Others minor changes:

- Simplified expression if (plant != null && isPlanted != null && showSnackbar != null) to if (plant != null && showSnackbar != null) as (isPlanted != null) is always true.
- Replaced deprecated Icons.Filled.ArrowBack with Icons.AutoMirrored.Filled.ArrowBack.
arriolac added a commit to android/sunflower that referenced this issue Jan 10, 2024
… composable. (#945)

The SunflowerImage() wrapper was introduced as a workaround for the issue bumptech/glide#4977, and now that the issue has been resolved, there is no need for this wrapper in the codebase.

Others minor changes:

- Simplified expression if (plant != null && isPlanted != null && showSnackbar != null) to if (plant != null && showSnackbar != null) as (isPlanted != null) is always true.
- Replaced deprecated Icons.Filled.ArrowBack with Icons.AutoMirrored.Filled.ArrowBack.

Co-authored-by: Chris Arriola <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants