5

I just tried to load an image from my resources with val context = ambient(ContextAmbient) but when I try to run the project I get an error during the generation of the code.

java.lang.IllegalStateException: Backend Internal error: Exception during code generation

@Composable
fun MovieImage(image: Int) {
    val context = ambient(ContextAmbient)
    Container(modifier = Modifier.None, width = 24.dp, height = 24.dp) {
        DrawImage(image = imageFromResource( context.resources, image))
    }
}
Calos
  • 1,783
  • 19
  • 28
  • Is there more to the error message? It's hard to diagnose without the full stack trace – Ryan M Feb 10 '20 at 19:11
  • yes, It says this too Element is unknownThe root cause java.util.NoSuchElementException was thrown at: androidx.compose.plugins.kotlin.compiler.lower.ComposableCallTransformer.irComposableExpr(ComposableCallTransformer.kt:1362) – Amancaya Iriarte Negron Feb 11 '20 at 11:22

1 Answers1

4

I ran in to the same problem when upgrading from 0.1.0-dev03 to 0.1.0-dev05. It was solved by adding composeOptions{ kotlinCompilerExtensionVersion "0.1.0-dev05" } to my build.gradle like this:

android {
    // ... other gradle properties

    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion "0.1.0-dev05"
    }
}
Michiel Dral
  • 3,932
  • 1
  • 19
  • 21
  • You may find a more recent version over here: https://developer.android.com/jetpack/androidx/releases/compose – Traendy Jul 03 '21 at 15:51