Missing common classes on a KMM project when integrated in an Android App as a Gradle project
Asked Answered
S

0

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?

Shroudlaid answered 8/3, 2022 at 15:15 Comment(3)
Hello, @elcolto! This seems like a problem caused by the current state of the kotlin-multiplatform Gradle plugin. Consider filing an issue at kotl.in/issue.Chun
Related Kotlin Issue: youtrack.jetbrains.com/issue/KT-52356Shroudlaid
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?Curch

© 2022 - 2024 — McMap. All rights reserved.