简体   繁体   中英

Use maven-publish to publish Android apk and aar with build variant (Android Gradle plugin 4.0)

I'm trying to followhttps://developer.android.com/studio/build/maven-publish-plugin to publish library (aar) module and application (apk) module to Maven repository ( maven-publish plugin). I'm using Kotlin Gradle kts instead of Grovy.

Sample publish in Grovy (from link above)

publishing {
    publications {
        paidRelease(MavenPublication) {
          // The following applies a component to this publication
          // which results in publishing an app bundle.
          from components.paidRelease_aab

          groupId = 'com.example.MyApp'
          artifactId = 'paid-release-aab'
          version = '1.0'
        }
        paidDebug(MavenPublication) {
          // The following applies a component to this publication
          // which results in publishing APKs in a ZIP file.
          from components.paidDebug_apk

          groupId = 'com.example.MyApp'
          artifactId = 'paid-debug-apks'
          version = '1.0'
        }
    }
}

My kotlin dls publishing code for app module

publications {
    create<MavenPublication>("mastercardMavenApk") {
        groupId = ProjectInfo.groupId
        artifactId = ProjectInfo.artifactId
        version = ProjectInfo.nexusVersion + if (useReleaseRepo) "" else "-SNAPSHOT"

        from(components["mastercardDebug_apk"])
    }
}

where mastercardDebug is one of my Active Build Variant

I always have below error:

SoftwareComponentInternal with name 'mastercardDebug_apk' not found

What should be the correct way to use maven-publish plugin for Android project (support both aar and apk module)?

just use print(components.names) before from(components["mastercardDebug_apk"]) to verify that the component exsists. maybe its just a typo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM