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

Shan

01/12/2020, 8:22 AM
If I have a multi-module program, and one of the project is kotlin multiplatform and the other is not, is there a way to get it to depend on the multiplatform module in the dependencies block? e.g.-
Copy code
//project: android-local

//android config omitted

dependencies {
    api(project(":android-remote"))
}
and then I have a mpp (in the same repo, different module)
Copy code
//project: android-remote

kotlin {
    jvm()
    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("core-lib") //an example
            }
        }

        val jvmMain by getting {
            //depends on commonMain by default
        }
    } 
}
using
api(project(":android-remote"))
does not add anything from
android-remote
to the dependencies of
android-local
. Is there some way I need to specify the target it since
android-remote
is a MPP? Or is this not possible?
u

Ugi

01/12/2020, 1:11 PM
Do you have
Copy code
enableFeaturePreview("GRADLE_METADATA")
In your project
settings.gradle
s

Shan

01/13/2020, 9:22 PM
I do!
u

Ugi

01/14/2020, 11:25 PM
Huh, it should work then but it could be a bunch of different reasons why it doesn't. I have a working sample android project that imports the mp module from the same project here https://github.com/ionspin/kotlin-multiplatform-bignum/blob/android/android-usage-sample/build.gradle.kts you just need to replace
implementation("com.ionspin.kotlin:bignum:0.1.5")
with
implementation(project(":bignum"))
. Maybe you'll spot some differences there that could help you.
s

sikri

01/19/2020, 8:45 AM
Try to close project, delete all .iml files, .idea, .build, .gradle, and re-import project in the end
I couldn’t make jvm module to see non-android jvm module (I got both android() and jvm() source targets) and it didn’t work until full reimport of the project
s

Shan

01/19/2020, 8:51 AM
I have reimported twice already unfortunately. No dice.
s

sikri

01/19/2020, 8:54 AM
hm, you can do this as workaround: to android-local (nonmpp!) add mpp plugin for example, this is mine:
Copy code
plugins {
    id("com.android.application")
    kotlin("multiplatform")
    kotlin("android.extensions")
    kotlin("kapt")
    id("kotlinx-serialization")
}
after
android { ... }
put
Copy code
kotlin {
    android()
}
The only problem is with
kapt
, as for now I have to write
"kapt"(someDep)
instead of
kapt(someDep)
s

Shan

01/19/2020, 10:39 PM
The only issue is that it doesn't include sources, so that's a bit annoying. Will have to figure out how to do that as well..
I actually refactored this a bit by using @sikri’s solution and the
jvmDefault
configuration in order to get the project sources to point to the correct project instead of the sources jar. I added the multiplatform plugin to my android library and used the
android()
setup as specified above, but used
jvmDefault
as the configuration for the project as I didn't want a specific android target on my
android-remote
mpp. Everything works great now!
7 Views