androidmavengradleandroid-gradle-pluginmaven-publish

Maven publish creates empty jar while publishing android artifacts


I have created several Kotlin & Android libraries and organised them in multiple Java/Kotlin & Android modules, respectively, and would like to publish them to a remote repo using maven-publish. All the modules are part of a single project.

Publishing works fine for Java/Kotlin modules, however, publishing Android modules results in an empty classes.jar file. Android Manifest and resources are published as expected and can be consumed while using the remote library.

AGP: 8.1.0
Kotlin: 1.8.21
Android Studio: Giraffe | 2022.3.1

Here's my Gradle file for the Android lib:

plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'kotlin-parcelize'
    id 'maven-publish'
}

apply from: '../defaultAndroidConfig.gradle'

android {
    namespace 'com.some_namespace'
}

dependencies {
    implementation androidDependencies.androidCoreKtx
    implementation androidDependencies.appCompat
    implementation androidDependencies.material
    implementation androidDependencies.constraintLayout

    implementation loggingDependencies.timber

    testImplementation testingDependencies.jUnit
}

publishing {
    publications {
        release(MavenPublication) {
            groupId = 'com.groupId'
            artifactId = 'artifact-id'
            version = "$version"

            afterEvaluate {
                from components.release
            }

            pom {
                developers {
                    developer {
                        id = 'devId'
                        name = 'devName'
                        email = 'devMail'
                    }
                }
            }
        }
    }
    repositories {
        maven {
            name = "GitHubPackages"
            url = uri("https://maven.pkg.github.com/myRepo")
            credentials {
                username = localProps.getProperty('github.username')
                password = localProps.getProperty('github.token')
            }
        }
    }
}

And here's defaultAndroidConfig.gradle:

android {
    compileSdkVersion androidCompileSdkVersion

    defaultConfig {
        minSdkVersion androidMinSdkVersion
        targetSdkVersion androidTargetSdkVersion

        aarMetadata {
            minCompileSdk = androidMinSdkVersion
        }

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = jvmTargetVersion
    }

    buildFeatures {
        viewBinding true
    }

    publishing {
        singleVariant('release') {
            withJavadocJar()
            withSourcesJar()
        }
    }
}

I'm using ./gradlew :android-lib:publish to publish the lib.

Once loaded to other projects, this is the result (first one being the Kotlin lib, where everything is published well, and the second one being the Android lib, where the classes are missing). enter image description here

While publishing with --info, publishReleasePublicationToGitHubPackagesRepository is not up-to-date because Task has not declared any outputs despite executing actions caught my eye, everything else seemed to be okay.

What am I doing wrong? 😄

Thanks in advance for any help!


Solution

  • I had minifyEnabled set to true. Changing to false is good enough for the library's intended purpose and everything works fine.