https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
m

Mustafa Ozhan

10/09/2020, 2:54 PM
Hello guys, I have a question, I created project with standart Android Studio KMM plugin. And then I added also my
backend
module into project as
jvm
target but surprisingly backend Module is not seeing
commonJvm
rather it sees
commonAndroid
expected values. Also I can not reach the class in
commonMain
from
backend
module. Did anyone had similar issue ? You can see the gradle.kts files in thread
backend build.gradle.kts
common build.gradle.kts
a

Ali Albaali

10/09/2020, 2:57 PM
You can't have Android and JVM applications in the same project yet. I think there's an open issue for that.
m

Mustafa Ozhan

10/09/2020, 2:59 PM
Ohh really 🤔 but I have seen some repos with both JVM and Android. Like https://github.com/jarroyoesp/KotlinMultiPlatform https://github.com/joreilly/PeopleInSpace
a

Ali Albaali

10/09/2020, 3:09 PM
There are, but I don't think they work TBH, but I could be wrong.
m

Mustafa Ozhan

10/09/2020, 3:09 PM
PeopleInSpace, works on my local
a

Ali Albaali

10/09/2020, 3:16 PM
Are you sure? Cuz as I remember on one of my projects, i tried it and it didn't work, I came across this tho https://stackoverflow.com/questions/59479020/how-to-share-java-code-between-android-and-jvm-targets-with-kotlin-multiplatfor but didn't work either.
m

Mustafa Ozhan

10/09/2020, 4:57 PM
Yes, but it is weird, i add some classes in PeopleInSpace it behaved like how it is for me On the other
PeopleInSpaceApi
(located in
commonMain
) https://github.com/joreilly/PeopleInSpace/blob/master/common/src/commonMain/kotlin/com/surrus/common/remote/PeopleInSpaceApi.kt can be reachable from
backend
module should be some trick to achieve this, I created a new class in same file couldn’t reach it
s

sergiocarabantes

10/10/2020, 9:49 AM
Hi guys, i have exactly the same issue. I don't understand why in PeopleInSpace project is working... hmm 🤔
m

Mustafa Ozhan

10/10/2020, 12:40 PM
@John O'Reilly maybe you can explain us since you are the repository owner 🙂
j

John O'Reilly

10/10/2020, 1:53 PM
If you can fork PeopleInSpace and repo issue you're seeing I'll try and get some time later to take a look
m

Mustafa Ozhan

10/10/2020, 2:16 PM
Hey, No we do not see any issue your repo works fine 🙂 and we wonder how you managed to access
commonMain
classes in
backend
module. Is there any trick for that ? It seems we are having issues and
backend
module only sees
androidMain
for some reason.
j

John O'Reilly

10/10/2020, 2:17 PM
"i add some classes in PeopleInSpace it behaved like how it is for me" was referring to this....sounded like you were able to reproduce same issue using PeopleInSpace (by adding some class?)...but I might have misunderstood?
I guess main thing is that following is in
backend
module gradle file but presume you probably something like that in your project as well?
Copy code
implementation(project(":common"))
m

Mustafa Ozhan

10/10/2020, 2:25 PM
yeap i have
Copy code
implementation(project(":common"))
but something is still missing, On the other hand I download your repo, you have
PeopleInSpaceApi
class in
commonMain
and you can use it in
Server.kt
, tested working, I created
TestCommon
class in same file couldn’t access it in
Server.kt
So I started to wonder if there is any extra step to make
commonMain
files visible in
backend
module
j

John O'Reilly

10/10/2020, 2:28 PM
I don't believe I did anything else specifically to allow that (though perhaps did so inadvertently 🙂 )
s

sergiocarabantes

10/10/2020, 2:31 PM
Thanks John. Which version of AS are you using? I tried stable, alpha, beta and I have the same issue in my personal project like @Mustafa Ozhan Still wondering why it only works in your project only 🙂
j

John O'Reilly

10/10/2020, 2:32 PM
I'm using 4.2 Canary 13 at the moment (have to use that for Jetpack Compose right now)
m

Mustafa Ozhan

10/10/2020, 2:37 PM
To clarify the weird problem please check the video 🙂 I hope I demonstrated it good 🙂
Meanwhile, I downloaded
4.2 Canary 13
and tested results are same
j

John O'Reilly

10/10/2020, 3:04 PM
so, I tried to replicate that here....like you it didn't show
TestCommonMain
as option as I was typing it.....but....was able to add as import and could resolve it then
Copy code
import com.surrus.common.TestCommonMain
so perhaps some issue with AS
m

Mustafa Ozhan

10/10/2020, 3:11 PM
Interesting 😕 manually not working for me either, will try to clean Android Studio compeletelly and use latest version
s

sergiocarabantes

10/10/2020, 3:55 PM
@Mustafa Ozhan Finally I got it. Clean everything. Remove .gradle, .idea, build folders for every single module. After that, invalidate caches and restart. Now I can have access to 'commonMain' 🙂
I just did this using 4.2 Canary 13
m

Mustafa Ozhan

10/10/2020, 4:52 PM
Okay finally I make it work too 🙂 thanks a lot guys 🙂