When I use Jetbrains Compose in Android Studio in ...
# compose-desktop
e
When I use Jetbrains Compose in Android Studio in an Android source set, and I use an
@Preview
is there any way to get it to use Android Studio's compose preview?
d
Preview annotation works in Android Studio for Android sourceset's.
e
I had issues with both of those scenarios. What's the best place to file a bug for each of them?
d
Sorry, I am wrong. The second plugin works for IntelliJ IDEA too. https://plugins.jetbrains.com/plugin/16541-compose-multiplatform-ide-support
Can you please try it in IDEA with this project: https://github.com/JetBrains/compose-jb/tree/master/templates/desktop-template In main.kt you can find Preview annotation
e
I'll try that soon, but I experienced issues in Android Studio. Previews weren't working in Android source sets, and when I installed the Compose Multiplatform IDE Support plugin compose references throughout my project weren't found and instead of a quick action to import them, the only option was to add a gradle dependency to the artifact where that reference lives.
d
You need Preview annotation for Android sourceSet in AndroidStudio?
e
Yes, if I want to preview a composable. I was able to deploy a preview to a device, but not show the preview in the IDE itself
d
For AndroidStudio and Android sourceSet doc available here: https://developer.android.com/jetpack/compose/tooling
You need this dependencies:
Copy code
debugImplementation("androidx.compose.ui:ui-tooling:1.3.0")
implementation("androidx.compose.ui:ui-tooling-preview:1.3.0")
e
So I can't use the compose Multiplatform artifact that gets re-written to use the Android one?
d
You can use the default AndroidStudio Preview with Android part of your app.
But, you need to split dependencies between common and Android part
e
I'll give that a shot as well
d
I can create basic sample for this scenario
Do you need it?
e
Thank you, I have a project that I can use for that pretty quickly. Just need to get back to my computer 😅
Looks like the issue is that Android Studio preview doesn't work if the Jetbrains Compose Gradle plugin is applied to the project
d
I will check it, thanks!
I investigate this problem. So, it works in the Android module. And in common module for Desktop. Video:

https://youtu.be/7XdLfsbPRqEâ–¾

Project: https://github.com/dima-avdeev-jb/check-android-studio-with-compose-mpp-preview I used this plugin https://plugins.jetbrains.com/plugin/16541-compose-multiplatform-ide-support
e
Ok thanks! Is it supposed to work in an Android source set in a multiplatform module? Also what version of Android Studio is that?
d
message has been deleted
2021.3.1 Patch 1
Is it supposed to work in an Android source set in a multiplatform module?
No, I tried, but Preview is not shown. But you may use a fast run option. To run this Preview right in emulator.
It works in android module
e
Ok thanks
118 Views