6

I have an existing Android app where I like to integrate a KMM library project as a git submodule. We want to integrate a git submodule on local builds and using a maven repository dependency on CI builds.

To achieve this, I added the directory of the submodule in my settings.gradle via includeBuild and substitute all dependencies of a specific module:

includeBuild('my-kmm-library-project') {
    dependencySubstitution {
        substitute module('com.example.any-kmm-artifact:any') using project(':any')
    }
}

Adding

implementation 'com.example.any-kmm-artifact:any:1.0.0'

to my application build.gradle file allows access to all classes and packages in the android sourceset int the submodule /my-kmm-library-project/any/src/androidMain. But I have no option to import "classes" from the commonMain sourceset. I already tried to let androidMain depend on commonMain.

kmm/build.gradle.kts:

val androidMain by getting {
    dependsOn(commonMain)
    ...

}

This doesn't lead to any success.

I also tried to add a jvm() target on KMM project and let jvmMain depend on androidMain, but this produces compile error, cause the Android SDK classes cannot be resolved.

I think the main problem is that, the classes are just compiled into the aar which can be assembled. But the module is integrated as a gradle project implementation.

Is there a KMM option to compile "common classes" and access them through a gradle module?

Kai Huppmann
  • 10,705
  • 6
  • 47
  • 78
elcolto
  • 961
  • 7
  • 11
  • 2
    Hello, @elcolto! This seems like a problem caused by the current state of the kotlin-multiplatform Gradle plugin. Consider filing an issue at https://kotl.in/issue. – Artyom Degtyarev Mar 22 '22 at 10:49
  • 2
    Related Kotlin Issue: https://youtrack.jetbrains.com/issue/KT-52356 – elcolto Jun 03 '22 at 06:38
  • Did you get any solution for this issue.... in my case, i'm able to access the common module classes... but it throws a error like no classdef found for ContentNegotiation... when i check in the project view seems like the ktor-content-negotiation library alone not downloaded ... do you have any fix for this? – Venkataramanan Aug 24 '22 at 18:25

0 Answers0