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

When targeting Android for a KMP project using Coil 3.0.0-alpha06, attempting to use .toBitmap() and .asComposeImageBitmap() results in Unresolved reference #2246

Closed
realityexpander opened this issue May 10, 2024 · 6 comments
Labels
help wanted Issues that are up for grabs + are good candidates for community PRs

Comments

@realityexpander
Copy link

realityexpander commented May 10, 2024

Describe the bug
This problem only exists on Android for KMP.

Attempting to use the results of a pre-loaded imageLoader.execute(imageResquest).image in an Image Composable by converting it using .toBitmap() and .asComposeImageBitmap() results in a compile-time errors:

Unresolved reference: toBitmap
Unresolved reference: asComposeImageBitmap

Note:

  • When targeting iOS, Desktop or Javascript works as expected with no problems.
  • Using the normal coil3 AsyncImage works as expected in Android when using just imageRequest.

I'm not sure if this is a configuration issue, I checked all the examples and the Coil 3 upgrade guide, and could see no differences.

To Reproduce
Here's the line that won't compile when targeting Android:
https://github.com/realityexpander/CloudCoverUSA2/blob/56d7575ac95903974b099738a015994aa5fdb972/composeApp/src/commonMain/kotlin/App.kt#L302

Code:
https://github.com/realityexpander/CloudCoverUSA2/releases/tag/coil3.alpha06.bug.report

Logs/Screenshots
image

Version
What library version are you using? Does this occur on a specific API level or Android device?
coil 3.0.0.alpha-06

@realityexpander realityexpander changed the title When targeting Android for a KMP project using Coil 3.0.0-alpha06, attempting to use .toBitmap() and .asComposImageBitmap() results in Unresolved reference When targeting Android for a KMP project using Coil 3.0.0-alpha06, attempting to use .toBitmap() and .asComposIemageBitmap() results in Unresolved reference May 10, 2024
@realityexpander realityexpander changed the title When targeting Android for a KMP project using Coil 3.0.0-alpha06, attempting to use .toBitmap() and .asComposIemageBitmap() results in Unresolved reference When targeting Android for a KMP project using Coil 3.0.0-alpha06, attempting to use .toBitmap() and .asComposeImageBitmap() results in Unresolved reference May 10, 2024
@colinrtwhite colinrtwhite added the help wanted Issues that are up for grabs + are good candidates for community PRs label May 10, 2024
@colinrtwhite
Copy link
Member

colinrtwhite commented May 10, 2024

Thanks for the repro. I believe this is a Compose Multiplatform/Skia error. Compose Multiplatform exposes org.jetbrains.skia.** classes and allows them to be referenced from common code, but the Skia dependency isn't available on Android and will fail to compile. You can trigger the same error by adding a reference to org.jetbrains.skia.Bitmap in common code.

To fix this you'll have to create an expect/actual function that uses the Skia Bitmap.asComposeImageBitmap on non-Android platforms and an implementation to convert android.graphics.Bitmap into an ImageBitmap on Android platforms (though I'm not sure about the specific method for that unfortunately).

@realityexpander
Copy link
Author

It's very strange, because the project builds and compiles for the other platforms... I'm sure this is going to be a common issue for people using the library on Android.

Is this something that sounds worthwhile to fix for Android?

@colinrtwhite
Copy link
Member

It's an issue with how Compose Multiplatform exposes its Skia dependency - not Coil. Coil only exposes the Skia dependency on non-Android platforms. It's not possible to fix from Coil's code. I'd recommend reporting the issue to the Compose Multiplatform team.

@colinrtwhite colinrtwhite closed this as not planned Won't fix, can't repro, duplicate, stale May 10, 2024
@realityexpander
Copy link
Author

I see that it's a Skia dependency issue, and you are still recommending that I create a custom solution for it or ask JetBrains to fix it?

Is this the final answer?

@realityexpander
Copy link
Author

I have submitted the issue at Compose Multiplatform team:

JetBrains/compose-multiplatform#4797

@colinrtwhite
Copy link
Member

The issue is asComposeImageBitmap shouldn't be exposed to common code at all by the Compose Multiplatform library since it's not present on Android. It's expected that it would be unresolved when compiling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issues that are up for grabs + are good candidates for community PRs
Projects
None yet
Development

No branches or pull requests

2 participants