https://kotlinlang.org logo
r

Robert Munro

06/28/2021, 6:40 AM
i have a
jvmMain
and an
androidMain
source folder in my shared module. It seems like l have to duplicate the actual class declaration in both jvmMain and androidMain as if I just have the jvm version the expected class says something like "there isnt an actual declaration for jvm" (referring to androidMain). If i delete my android source set and gradle declaration the shared library complains about a missing
AndroidManifest.xml
. So just wondering if it is normal that i would have to duplicate
androidMain
and
jvmMain
s

Sourabh Rawat

06/28/2021, 7:08 AM
Maybe try making androidMain depend on jvmMain
r

Robert Munro

06/28/2021, 7:17 AM
I ont guess you have any tips on how to do it for kts? For gradle i do
Copy code
sourceSets {
test {
    java.srcDir 'src/sharedTest/java'
}
}
but there seems to be no srcDir function for kts
s

Sourabh Rawat

06/28/2021, 7:19 AM
dependsOn(jvmMain)
in the
androidMain
is how you normally make dependent sourcesets.
✔️ 1
r

Robert Munro

06/28/2021, 7:22 AM
yes that works a treat .. thanks 🙂
s

Sourabh Rawat

06/28/2021, 7:23 AM
Did it solve the expect/actual issue you were facing?
j

Javier

06/28/2021, 7:54 AM
another approach if you dont want to share all jvm, is having a folder called something like androidAndJvm and add it to both sourcesets (you can see this approach in compose-jb samples)
r

Robert Munro

06/28/2021, 7:55 AM
@Sourabh Rawat yes it worked thanks
@Javier thanks good to know ... actually all my classes are the same atm but that would be better
19 Views