https://kotlinlang.org logo
Title
c

Colton Idle

06/01/2021, 4:12 PM
Sorry in advance for my questions. I am converting my plain old android + compose project (composable are in a separate module... ready to share!) to JB compose with multiplatform. I will use threads, for each question I encounter. 1. Converting my android compose project to be multiplatform compose... what do I do with these dependencies in my android app modules build.gradle?
// Compose version = 1.0.0-beta07
    api("androidx.compose.ui:ui:$composeVersion")
    implementation("androidx.compose.ui:ui-tooling:$composeVersion")
    implementation("androidx.compose.foundation:foundation:$composeVersion")
    api("androidx.compose.material:material:$composeVersion")
    implementation("androidx.compose.ui:ui-util:$composeVersion")

    implementation("androidx.compose.material:material-icons-core:$composeVersion")
    implementation("androidx.compose.material:material-icons-extended:$composeVersion")
Looks like they can basically be swapped with these. Is that right?
api(compose.runtime)
api(compose.foundation)
api(compose.material)
api(compose.materialIconsExtended)
i

Igor Demin

06/01/2021, 4:53 PM
The equivalent would be:
api(compose.ui)
    implementation(compose.foundation)
    api(compose.material)
    implementation(compose("orj.jetbrains.compose.ui:ui-util")

    implementation(compose.materialIconsExtended)
material-icons-core
is already the part of
material
Not sure about
ui-tooling
. MPP doesn't has it, even only for android. Probably you have to use the androidx version. But because it is built from the different revision there can be some bugs. Actually MPP has `ui-tooling`:
implementation(compose("org.jetbrains.compose.ui:ui-tooling")
But don't know if it will work, there some issues that we still haven't resolved / investigated.
👍 1
u

uli

06/02/2021, 8:02 AM
> Could not find org.jetbrains.compose.ui:ui-tooling-data:0.4.0.
     Searched in the following locations:
       - <https://dl.google.com/dl/android/maven2/org/jetbrains/compose/ui/ui-tooling-data/0.4.0/ui-tooling-data-0.4.0.pom>
       - <https://repo.maven.apache.org/maven2/org/jetbrains/compose/ui/ui-tooling-data/0.4.0/ui-tooling-data-0.4.0.pom>
       - <https://maven.pkg.jetbrains.space/public/p/compose/dev/org/jetbrains/compose/ui/ui-tooling-data/0.4.0/ui-tooling-data-0.4.0.pom>
     Required by:
         project :androidApp > project :shared > org.jetbrains.compose.ui:ui-tooling:0.4.0 > org.jetbrains.compose.ui:ui-tooling-android-debug:0.4.0
Seems it is not yet ready 😞
could the missing artifact be uploaded? or is it currently not buildable?
i

Igor Demin

06/02/2021, 8:21 AM
It is currently android-only, unfortunately.
But it seems we only need it for android, so we can try to upload it
❤️ 1
We published
0.0.0-unmerged-build79
that is the copy of
0.4.0
but with
ui-tooling-data
(it is hard to just add a single artifact without rebuilding the entire library, but it will be available in 0.4.1/0.5.0-buildXXX)
c

Colton Idle

06/02/2021, 5:38 PM
@Igor Demin when I add this line I get this error for missing an import. Sorry I'm a gradle noob. Is importing really needed or is this
compose("...")
function not working properly?
i

Igor Demin

06/02/2021, 5:42 PM
what are the imports at the top of build.gradle.kts?
It should be
import org.jetbrains.compose.compose
Probably it conflicts with the android function 🤔
c

Colton Idle

06/02/2021, 5:46 PM
@Igor Demin I have no imports at the top!
i

Igor Demin

06/02/2021, 5:46 PM
Then add it 🙂
import org.jetbrains.compose.compose
Without import this will not work
c

Colton Idle

06/02/2021, 5:47 PM
Gotcha. Yeah I wasn't sure if the
compose()
call was broken and didn't need the import since I didn't need the import for anything JB compose related until today. Just triple checking. Thank you!
@Igor Demin one last issue I'm running into. So what's the solution for this import that is missing in JB compose?
import androidx.compose.ui.tooling.preview.Preview
1. Use
implementation(compose("org.jetbrains.compose.ui:ui-tooling-data"))
2. Or use
implementation(compose("org.jetbrains.compose.ui:ui-tooling-data"))
3. Or remove it because @Preview annotation is not MPP yet and so it's easiest to not have it at all until support for it is built 4. Or Change imports to
androidx.compose.desktop.ui.tooling.preview
Its funny because I actually don't really rely on Preview all the much. But I have a SINGLE composable in my common module that has @Preview annotation.
i

Igor Demin

06/02/2021, 7:36 PM
As I mention before, I don't have an answer for that. Preview is still not friendly with MPP compose, at least with desktop target. Theoretically it can work in Android Studio in androidMain when we use: 1. compose
0.0.0-unmerged-build79
and
implementation(compose("org.jetbrains.compose.ui:ui-tooling"))
2. or compose
0.4.0
and
implementation("androidx.compose.ui:ui-tooling:1.0.0-beta07")
3. or compose
0.4.0
and
implementation(compose("org.jetbrains.compose.ui:ui-tooling"))
and
implementation("org.jetbrains.compose.ui:ui-tooling-data:0.0.0-unmerged-build79")
But it is just a guess, I haven't tried it.
import probably would be resolved, but don't know if preview will be displayed in Android Studio and will there be errors on build or in studio's log
c

Colton Idle

06/02/2021, 7:40 PM
Yeah. I don't care about preview working, I just want the import to be resolved for now so I don't have to modify my code. But this is for the common module, so I don't think my dependency would go into androidMain. I guess I'm asking if there's a dependency that can go into commonMain.
i

Igor Demin

06/02/2021, 7:42 PM
dependency that can go into commonMain
try
implementation(compose("org.jetbrains.compose.ui:ui-tooling"))
in
commonMain
and
implementation("org.jetbrains.compose.ui:ui-tooling-data:0.0.0-unmerged-build79")
in
androidMain
🆗 1
c

Colton Idle

06/02/2021, 7:42 PM
I saaw your answer before I just didn't realize that that meant you don't have a good answer for it since you later said that you published this:
We published 0.0.0-unmerged-build79 that is the copy of 0.4.0 but with ui-tooling-data
and that confused me some more because you said ui-tooling-data, and but the androidx artifact is ui-tools
I added:
implementation(compose("org.jetbrains.compose.ui:ui-tooling"))
to commonMain (nothing into androidMain just yet) just to try to see if it'll compile my shared composables. Got this error. Going to try that updated 0.0.0 version now.
Could not find org.jetbrains.compose.ui:ui-tooling-data:0.4.0.
     Searched in the following locations:
       - <https://dl.google.com/dl/android/maven2/org/jetbrains/compose/ui/ui-tooling-data/0.4.0/ui-tooling-data-0.4.0.pom>
       - <https://repo.maven.apache.org/maven2/org/jetbrains/compose/ui/ui-tooling-data/0.4.0/ui-tooling-data-0.4.0.pom>
       - <https://maven.pkg.jetbrains.space/public/p/compose/dev/org/jetbrains/compose/ui/ui-tooling-data/0.4.0/ui-tooling-data-0.4.0.pom>
       - <https://s3.amazonaws.com/salesforcesos.com/android/maven/release/org/jetbrains/compose/ui/ui-tooling-data/0.4.0/ui-tooling-data-0.4.0.pom>
       - <https://jitpack.io/org/jetbrains/compose/ui/ui-tooling-data/0.4.0/ui-tooling-data-0.4.0.pom>
       - <https://dl.bintray.com/google/flexbox-layout/org/jetbrains/compose/ui/ui-tooling-data/0.4.0/ui-tooling-data-0.4.0.pom>
     Required by:
Updated to 0.0.0-unmerged-build79 and I get
Duplicate class androidx.compose.ui.tooling.CompositionDataRecord found in modules ui-tooling-1.0.0-beta07-runtime (androidx.compose.ui:ui-tooling:1.0.0-beta07) and ui-tooling-debug-runtime (org.jetbrains.compose.ui:ui-tooling-android-debug:0.0.0-unmerged-build79)
...
...
I think I'll just leave it as:
0.4.0
 and 
implementation("androidx.compose.ui:ui-tooling:1.0.0-beta07")
as that allows my code to compile without changing anything. I don't care about Preview actually working. I just want my git commit to not change our DesignSystemComposables.kt file. And instead I just want my git diff to just show that I'm purely swapping out dependencies. Hopefully that makes sense as to why I want Preview to compile, but I don't care if it works. Thanks again Igor Demin. That's enough compose for desktop for today!
👍 1
u

uli

06/02/2021, 7:55 PM
And thanks for providing the unmerged build
And short feedback: Android preview works with 0.0.0-unmerged-build97
👍 1
c

Colton Idle

06/03/2021, 12:16 AM
@uli how'd you set it up? What dependency does commonMain have? What dep does androidMain have?
u

uli

06/04/2021, 11:41 AM
I just put ``implementation(compose("org.jetbrains.compose.ui:ui-preview"))` into the App’s build.gradle.kts to automatically keep versions in sync and the IDE picks it up just fine. I can also put it into androidMain’s build.gradle.kts to make `@Preview`` compile. But the IDE won’t pick it up and won’t render previews. I can also put it into commonMain - but depending on the traget platform the package of the
@Preview
anotation changes so there is no single source code that includes
@Preview
and compiles for all platforms.
c

Colton Idle

06/04/2021, 6:49 PM
@uli aha. Okay. I am trying to share my CommonComposables.kt file between desktop and android and inside of that I have a single preview annotation. Hence I was trying to see if there was a way to satisfy the compiler/import statements. I don't actually care if preview works, I just wanted to satisfy the compiler, but it sounds like you said "there is no single source code that includes 
@Preview
 and compiles for all platforms." I will just remove Preview from my CommonComposables.kt for now.
u

uli

06/05/2021, 11:47 AM
You could try to expect/actual the annotation and use typealiases
👍 1