Hello folks! Hope you are all doing great! I am f...
# multiplatform
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 ?: ""
                            }
                        }
                    }
                }
            }
        }
    }
}
p
Your assumption is not correct. Android doesn't do fat aars, you have to publish both and add both libraries/modules in the consumer App
In the java world there are a couple of plugins that do this module embedding stuff for you but Android had some challenges with the resources. There is a ticket open but seems to be buried in time. So the way is publishing all your modules and explicitly importing them in the consumer App
h
Thanks for answering. Thank you so much!
👍 1
p
I saw a recent post where somebody mentioned this gradle plugin. You can check if it does the job: https://github.com/deepmedia/Grease
h
I will try, thanks!