Skip to content
Discussion options

You must be logged in to vote

The problem is that the R.drawable constants are only available at the application-level module, to which only the scaffold of Android/app/src/main/kotlin/poackagename/Main.kt is part of. Everything in your SwiftPM project is converted to an embedded Android module project, and so does not have access to the top-level R constants.

However, you can look up the image by name at runtime. I just tried this out, and it seems to work:

@ViewBuilder func androidCustomImageView() -> some View {
    #if !SKIP
    EmptyView()
    #else
    // This module cannot access application-level `R.drawable` constants, so we need to look up the resource by name
    let ctx = androidx.compose.ui.platform.Local…

Replies: 4 comments 8 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@aabewhite
Comment options

Comment options

You must be logged in to vote
1 reply
@cleamaec
Comment options

Comment options

You must be logged in to vote
6 replies
@cleamaec
Comment options

@marcprux
Comment options

@cleamaec
Comment options

@marcprux
Comment options

@cleamaec
Comment options

Answer selected by marcprux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants