Maven publish 在发布 android 工件时创建空 jar

Maven publish creates empty jar while publishing android artifacts

提问人:Luja93 提问时间:8/17/2023 更新时间:8/18/2023 访问量:57

问:

我已经创建了几个 Kotlin 和 Android 库,并将它们分别组织在多个 Java/Kotlin 和 Android 模块中,并希望使用 maven-publish 将它们发布到远程存储库。所有模块都是单个项目的一部分。

发布适用于 Java/Kotlin 模块,但是,发布 Android 模块会导致文件为空。Android 清单和资源将按预期发布,并且可以在使用远程库时使用。classes.jar

AGP:8.1.0
Kotlin:1.8.21
Android Studio:长颈鹿 |2022.3.1

这是我的 Android 库的 Gradle 文件:

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')
            }
        }
    }
}

这里是: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()
        }
    }
}

我正在用来发布库。./gradlew :android-lib:publish

一旦加载到其他项目,这就是结果(第一个是 Kotlin 库,其中所有内容都发布得很好,第二个是 Android 库,其中缺少类)。enter image description here

在发布时,引起了我的注意,其他一切似乎都还好。--infopublishReleasePublicationToGitHubPackagesRepository is not up-to-date because Task has not declared any outputs despite executing actions

我做错了什么?😄

提前感谢您的任何帮助!

android maven gradle android-gradle-plugin maven-publish

评论


答:

0赞 Luja93 8/18/2023 #1

我已设置为.更改为足以满足库的预期目的,并且一切正常。minifyEnabledtruefalse