How do I enable preview for Android Studio of Comp...
# compose-android
j
How do I enable preview for Android Studio of Compose in androidMain? I have added the debug tooling and preview libs in android deps. And I also added compose previews into androidMain, but nothing happens. Do I need some magic flags somewhere or something?
j
Hmm no that I forgot to add, is kotlinCompilerExtensionVersion important as well?
Ok now something happened, thanks, however:
Copy code
The graphics preview in the layout editor may not be accurate: 
- The current rendering only supports APIs up to 33. You may encounter crashes if using with higher APIs. To avoid, you can set a lower API for your previews. (Ignore for this session)
πŸ˜„
Why cant multi platform things solve this mess. Its so annoying we get same problems over and over again from CMP, React Native, Flutter, Xamarin etc. Can we please get a nice decoupled thing like Gradle Amper deal with all this weirdness πŸ˜„
βž• 1
p
Check the version of the compose compiler might not be the latest. Perhaps another new one plays better with your versions
thank you color 1
Maybe those issues solve by 2026 πŸ˜„
j
Ah yeah I had to add the compose compiler, otherwise get into next shit from Gradle not automatic selecting correct kotlin compiler vs compose compiler. I got version 1.3.2 incompatible πŸ˜„ But next madness now is to solve all LocalCompositions not working xD
😁 1
@Pablichjenkov Do you happen to know if Jetbrains resources for images should work in preview? Looks like they do not, the resource file not found. I probably need some kind of hack to resolve the files by using true android resource qualifiers. Which is I guess why Jetbrains changed to that in recent main branch in upcoming 1.6 release I guess πŸ˜„
p
Just did a quick check and didn't see any of my few previews using images from resources. I think I never was able to do it. I might try later. Traditionally the JB resources API didn't play well with multimodule projects, and all my projects are. So let's wait and hope for 1.6, it is planned to fix lot of resources stuff.
j
Yeah I did my own wrapper on top of the Jetbrains resources as well. I was thinking about return a dummy painter or whatever until resolved but also not nice. It would be possible to use drawable painter reference instead, then I think would work in Android. Will test and see if I put my image inside drawable folder and copy resources into Android res folder πŸ˜›
Copy code
data class MyPainter(val relativePath: String) : MyImageSource {
        val painter: Painter
            @Composable
            get() {
                if (LocalInspectionMode.current) {
                    return rememberVectorPainter(Icons.Default.Add)
                }
                return painterResource(relativePath)
            }
    }
I test do it like this for now, not sure if good πŸ˜„
πŸ‘ 1
It does work, but looks ugly as F πŸ˜„
p
I remember it, I mean if it works it works !
501 Views