Harish Reddy
09/16/2024, 5:17 PMCoreModule
Module-2: FeatureModule
FeatureModule
references CoreModule
internally using api(project(path = ":CoreModule))
. The final artifact FeatureModule
after publishing to maven/maven local is supposed to be integrated in main Android app.
So, now my expectation is to have the code within CoreModule
to be accessible inside the main Android app since FeatureModule
includes the CoreModule
. But, I can’t access the code/classes within CoreModule
inside the main Android app. This is a KMP project which I am not so familiar with. So, not sure if it is a KMP thing or something else. Any idea what could be missing in this setup? I am attaching reference code in the thread.Harish Reddy
09/16/2024, 5:18 PM======build.gradle.kts=========
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
id("maven-publish")
id("com.example.kmpproject.library")
}
kmpProjectLibrary {
publishedArtifactId.set("FeatureModule")
}
kotlin {
androidTarget {
publishLibraryVariants("release")
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
val xcf = XCFramework()
listOf(iosArm64(), iosSimulatorArm64()).forEach {
it.binaries.framework {
export(project(":CoreModule"))
xcf.add(this)
baseName = "FeatureModule"
isStatic = true
binaryOption("bundleId", "com.example.kmmproject.FeatureModule")
}
}
sourceSets {
commonMain.dependencies {
implementation(libs.ktor.client.core)
// Including CoreModule
api(project(path = ":CoreModule"))
}
androidMain.dependencies {
// Including CoreModule
api(project(path = ":CoreModule"))
}
iosMain.dependencies {
implementation(libs.ktor.client.darwin)
}
}
}
android {
}
Harish Reddy
09/16/2024, 5:19 PMclass LibraryConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
val extension =
extensions.create<LibraryConventionPluginExtension>("kmmLibrary")
configureArtifactoryPublishing {
try {
extension.publishedArtifactId.get()
} catch (exception: MissingValueException) {
null
}
}
}
}
private fun Project.configureArtifactoryPublishing(artifactIdProvider: () -> String?) {
configure<LibraryExtension> {
configure<PublishingExtension> {
publishing {
repositories {
maven {
url = "sample url"
version = "1.0"
group = "com.example.kmm"
credentials {
username = properties["USERNAME"] as? String ?: ""
password = properties["PASSWORD"] as? String ?: ""
}
}
}
}
}
}
}
}
tapchicoma
09/18/2024, 8:01 AMAnton Lakotka [JB]
09/18/2024, 8:27 AM.*module
(you can find them in maven repository if you publish it locally) files of published libraries (CoreModule and FeatureModule). Or your androidApp depends on FeatureModule as project dependency?
Because indeed transitive dependencies should work correctly by default. And it is not clear what went wrongHarish Reddy
09/18/2024, 5:31 PMFeatureModule
as project dependency. The KMP project (which has CoreModule
and FeatureModule
is a separate project. When I try to publish artifact (maven & local maven) only for FeatureModule
that internally locally referencing CoreModule
, I am able to generate artifact only for FeatureModule
which is want to achieve. But I also want to access the classes residing in CoreModule
, when I call them from main Android app after adding FeatureModule
artifact as a dependency. In general, all the functionality (code depending on CoreModule
) works as expected as it is locally referenced from the FeatureModule
which is finally integrated in main Android app. The only issue is that, from main app, I can’t call/access the classes residing in CoreModule
although I am using api
instead of implementation
while referencing CoreModule
inside FeatureModule
. As per my understanding using api
should make the classes in CoreModule
available to the end consumer as well, not just to FeatureModule
. But this is not happening. I hope you got the issue.Anton Lakotka [JB]
09/30/2024, 11:11 AMI hope you got the issue.Kinda. I'm still not quite sure what you're doing.
1. the idea is that main Android app depends onIf you mean this. then Android app,as project dependency.FeatureModule
FeatureModule
and CoreModule
must be in the same Gradle Build
2. The KMP project (which hasWhat do you mean separate project? One Gradle Build with two Sub-Projects? Then this contradicts with the Statement 1. As Android App can't have such project dependency.andCoreModule
is a separate projectFeatureModule
When I try to publish artifact (maven & local maven) only forIf you publishthat internally locally referencingFeatureModule
, I am able to generate artifact only forCoreModule
which is want to achieveFeatureModule
FeatureModule
that depends on CoreModule
in runtime or compiletime doesn't matter. The CoreModule
must be published as well. Unless you "embed" classes from CoreModule to FeatureModule.
So I would prefer a reproducer here as I don't entirely sure where is the problem. from what I see rn, most likely your build is doing something wrong. And KMP is just making it way more harder.
May I propose you to approach this problem from different perspective:
1. create 3 small projects: Android, Feature and Core. Make them all to be very basic ones. And Feature and Core not KMP but just simple JAVA/Kotlin JVM.
2. try to see if you can achieve your needs in this small setup.
3. then do next step and convert Feature and Core into KMP.
4. If, after converting to KMP, your setup started to fail. Then please come back and I'll try to help you. Perhaps there is indeed some migration issues in KMP world.