Did Google update the DrawImage portion of the jetpack compose API?

  • Thread starter Thread starter greySky
  • Start date Start date
  • Tags Tags
    Google
Click For Summary
SUMMARY

The discussion centers on the unresolved reference error for the DrawImage function in Jetpack Compose while using Android Studio 4.0 Canary 8. The user encountered issues with both the DrawImage function and the R.drawable.header resource. The solution involved adding specific dependencies to the build.gradle file, including 'androidx.ui:ui-material:0.1.0-dev03', 'androidx.ui:ui-foundation:0.1.0-dev03', and 'androidx.ui:ui-tooling:0.1.0-dev03', which resolved the import issue for DrawImage. This highlights the importance of ensuring all necessary dependencies are included in the project setup.

PREREQUISITES
  • Familiarity with Jetpack Compose API
  • Understanding of Android Studio build.gradle configuration
  • Basic knowledge of Kotlin programming language
  • Experience with image resource management in Android development
NEXT STEPS
  • Research the latest Jetpack Compose documentation for image handling
  • Learn about dependency management in Android Studio projects
  • Explore the use of the Column composable in Jetpack Compose
  • Investigate common errors and troubleshooting techniques in Jetpack Compose
USEFUL FOR

Android developers, particularly those working with Jetpack Compose and troubleshooting image rendering issues, will benefit from this discussion.

greySky
Messages
4
Reaction score
2
https://developer.android.com/jetpack/compose/tutorial
in the "Add a picture" section

[CODE highlight="8"]@Composable
fun NewsStory(){
val image = +imageResource(R.drawable.header)
Column (modifier = Spacing(64.dp)){
Text("A day in shark fin cove")
Text("davenport")
Text("december 2018")
DrawImage(image)
}
}[/CODE]

Hovering over DrawImage shows: "Unresolved reference: DrawImage", There is no auto import option for this error as there was with "Column" earlier in the tutorial.

I am using Android Studio 4.0 Canary 8
Is my local setup or the linked tutorial out of date? what is the current method to add an image

PS
I actually had two problems, "R.drawable.header" had some error I cannot remember the error text for this error but applying
https://stackoverflow.com/a/49743044
fixed the issue with R.drawable.header", but the DrawImage error persisted.
 
Technology news on Phys.org
found the answer:
[CODE title="build.gradle (:app) [excerpt]" highlight="5"]dependencies {

...
implementation 'androidx.ui:ui-material:0.1.0-dev03'
implementation 'androidx.ui:ui-foundation:0.1.0-dev03'
implementation 'androidx.ui:ui-tooling:0.1.0-dev03'
...

}[/CODE]

Line 5 was missing in the default build.gradle (:app). Adding the line enables the auto-add-import-statement option (under alt-enter like most jetbrains IDEs)

I suppose adding the line for "foundation" (after searching the androidx reference for DrawImage)
https://developer.android.com/reference/kotlin/androidx/ui/foundation/package-summary
would make sense to experienced developers. However following a naive path through the existing tutorial and setup instructions does not make this obvious.
 
  • Like
Likes   Reactions: jim mcnamara