Hi! I would appreciate some help with understandin...
# multiplatform
v
Hi! I would appreciate some help with understanding artefacts I can build from KMP code for Android. I have a KMP library with 2 modules: analytics and domain. Analytics depends on domain, it is declared like this:
Copy code
plugins {
    kotlin("multiplatform")
    id("com.android.library")
    `maven-publish`
}

kotlin {
    androidTarget {
        publishAllLibraryVariants()
    }
    iosX64()
    iosArm64()
    iosSimulatorArm64()

    applyDefaultHierarchyTemplate()

    sourceSets {
        val commonMain by getting {
            dependencies {
                api(project(":domain")) <--- HERE
            }
        }
    }
}

android {
    compileSdk = libs.versions.compileSdk.get().toInt()

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    defaultConfig {
        minSdk = libs.versions.minSdk.get().toInt()
    }
    namespace = "com.temper.works.analytics"
}

addGithubPackagesRepository()
To debug my changes from Android app I try to build as less artefacts as possible, I thought running
publishAndroidReleasePublicationToMavenLocal
and
publishAndroidReleasePublicationToMavenLocal
would be enough. When I try to build only android artefacts and resolve them from maven local in my Android app, gradle complains that it needs a domain (not domain-android) artefact. I add a dependency in my Android app in a trivial way, nothing special:
Copy code
api("com.temper.works:analytics-android:0.1")
Build error looks like that:
Copy code
Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':freeflex:mergeDebugAssets'.
> Could not resolve all files for configuration ':freeflex:debugRuntimeClasspath'.
   > Could not find com.temper.works:domain:0.1.
     Searched in the following locations:
       - <https://dl.google.com/dl/android/maven2/com/temper/works/domain/0.1/domain-0.1.pom>
       - file:/Users/sokolova/.m2/repository/com/temper/works/domain/0.1/domain-0.1.pom
       ...
     Required by:
         project :freeflex > project :freeflex-core > com.temper.works:analytics-android:0.1
I would expect it to use
com.temper.works:domain-android
🤔 Can someone help me to understand why it happens?
c
Did you publish
domain
also to your local maven? It’s a transitive dependency and is pulled from a maven repository as well.
h
It really depends on your full build, a build scan would be helpful.
v
@Chrimaeon I do publish
domain-android
and I would expect it to be enough, but it is not
I have a very simple project configuration right now: an umbrella project for iOS and two modules for Android. Analytics can't be used without domain, so I provide it through
api
@hfhbd This is the build scan https://scans.gradle.com/s/vam5ptrfcjku6
h
The build scan is successful without free-flex?
v
It's KMP project build scan, sorry for misunderstanding, the scan of Android project will be massive, I'm not sure you want to see it
but the native app idea is that
app
module (it is called "freeflex") includes
freeflex-core
(utility modules all features depend on):
Copy code
implementation(project(":freeflex-core"))
and
freeflex-core
has dependency on analytics-android KMP library:
Copy code
api("com.temper.works:analytics-android:0.1")
That's all we have.
h
I'm not sure you want to see it
Well, to help you the failure message is more interesting than a working build 😄
v
I guess, it's a KMP project using some shared common code too?
domain-android
only contains the android part
v
I thought the *aar we build will contain everything 🤔 including shared part.
Because if I unzip my *aar, I see classes from commonMain
h
Yes, the aar contains all classes which are used by Android later, but Gradle needs to resolve all dependencies first, here a normal
java-api
variant of your dependency, not the
aar
.
v
Hmm, ok, will take it into account in future. Thank you. One last question: where can I read more about such things, what gradle needs and how it resolves things? what should I google for? Can you suggest any specific parts of gradle documentation?