How to publish both Android apk and aab with android-gradle-plugin 8.2.0-rc02?

94 views Asked by At

I need to publish both apk and aab to my storage.

I use android-gradle-plugin 8.2.0-rc02 and trying to use the following code with kotlin-dsl:

plugins {
    id("com.android.application")
    kotlin("android")
    ...
    `maven-publish`
}

android {
   publishing {
        singleVariant("preprodRelease"){
            publishApk()
        }
        singleVariant("preprodRelease")
        singleVariant("prodRelease"){
            publishApk()
        }
        singleVariant("prodRelease")
   }

   ...
}

afterEvaluate {
    publishing {
       ...
    }
}

but when I try to do this I get an error:

Using singleVariant publishing DSL multiple times to publish variant "preprodRelease" to component "preprodRelease" is not allowed.

I studied the documentation: https://developer.android.com/build/publish-library/configure-pub-variants. The publication description is only for the library, not for the application. I found https://developer.android.com/reference/tools/gradle-api/8.2/com/android/build/api/dsl/ApplicationPublishing but there is no example of simultaneous publication of both apk and aab. Either one or the other. I need to publish both to my repository. If I remove the singleVariant with the publication, for example apk, then aab is published normally.

I found a multipleVariants publication, but it is ONLY for the library, https://developer.android.com/build/publish-library/configure-pub-variants#multiple-pub-vars

How can I set up apk and aab publishing for an application?

0

There are 0 answers