Hello folks! Hope you are all doing great! I am f...
# build-tools
h
Hello folks! Hope you are all doing great! I am facing some issues with Publishing Android library setup. Any help/pointers would be greatly appreciated. I have a KMP project with multi-module setup. Module-1:
CoreModule
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.
Copy code
======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 {
   
}
The Publishing artifact is handled using ConventionPlugin as below
Copy code
class 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 ?: ""
                            }
                        }
                    }
                }
            }
        }
    }
}
t
better to ask Gradle configuration questions in #C19FD9681 channel
h
Sure, thanks!