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
In the "Add a picture" section of the Jetpack Compose tutorial, users encounter an issue with the "DrawImage" function, which results in an "Unresolved reference" error. This problem arises when using Android Studio 4.0 Canary 8, leading to questions about whether the local setup or the tutorial is outdated. The user initially faced issues with "R.drawable.header," which were resolved by following a Stack Overflow solution. However, the "DrawImage" error persisted until the user discovered that adding specific dependencies to the build.gradle file was necessary. Including 'androidx.ui:ui-foundation:0.1.0-dev03' resolved the issue and enabled auto-import functionality. The discussion highlights that the tutorial does not clearly indicate the need for these dependencies, which could confuse less experienced developers navigating the setup process.
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 jim mcnamara
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...