https://kotlinlang.org logo
Title
i

Ion Carrera

05/17/2023, 2:25 PM
Hello I've created from android studio + plugin a hello world library (not app), which contains the "Greeting.kt" basic class. I want to publish it locally via maven (publishToMavenLocal). The publishing happens, the folder is created along the .pom. But no artifact at all is created, meaning no .aar nor .framework files are created. What am I missing?
plugins {
    //trick: for the same plugin versions in all sub-modules
    id("com.android.library").version("8.0.1").apply(false)
    kotlin("multiplatform").version("1.8.10").apply(false)
    id("maven-publish")
}

tasks.register("clean", Delete::class) {
    delete(rootProject.buildDir)
}

publishing {
    publications {
        create<MavenPublication>("release") {
            groupId = "com.ion.testkmm"
            artifactId = "testkmmion"
            version = "1.0"
        }
    }
}
l

Landry Norris

05/17/2023, 2:28 PM
There's something you have to add to the android target config to publish for android. I'm on mobile now, but I'll see if I can find it. What targets have you set up?
c

Casey Brooks

05/17/2023, 2:29 PM
maven-publish
needs to be applied to each submodule individually, not in the root project
l

Landry Norris

05/17/2023, 2:31 PM
android { 
         publishLibraryVariants("debug", "release") 
     }
You'll need this when you set up the android target. I think there's a new gradle 8.0+ way, but this is what I've used.
i

Ion Carrera

05/17/2023, 2:36 PM
android {
    namespace = "com.ion.testkmm"
    compileSdk = 33
    defaultConfig {
        minSdk = 24
    }

    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
        }
    }

    publishing {
        singleVariant("release")
    }
}

publishing {
    publications {
        create<MavenPublication>("release") {
            groupId = "com.ion.testkmm"
            artifactId = "testkmmion" //this is the "shared", that has been renamed
            version = "1.0"
        }
    }
}
still nothing, althought it created everyfolder like: testkmm, testkmm-android, testkmm-ios
kotlin {
    android {
        compilations.all {
            kotlinOptions {
                jvmTarget = "1.8"
            }
        }
        publishLibraryVariants("release")
    }
    
    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = "testkmmion"
        }
    }

    sourceSets {
...