2

我正在尝试创建一个胖 AAR 来分发我的 Android 库。我正在使用Mobbeel Fataar 插件将我的所有依赖项打包到 AAR 中,以便于分发。这完美地工作,当我运行时./gradlew build,我得到一个 AAR 文件,它在其目录mylibrary/build/outputs/aar/中包含我的所有依赖项。当我尝试分发 AAR 时,问题就出现了。mylibrary-release.aarlibs

为了分发,我找到了这个教程来指导我,我几乎没有使用它。这是代码(在我的build.gradle):

apply plugin: 'maven'
apply plugin: 'signing'

def isReleaseBuild() {
        return VERSION_NAME.contains("SNAPSHOT") == false
}

def getReleaseRepositoryUrl() {
        return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
                        : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
}

def getSnapshotRepositoryUrl() {
        return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
                        : "https://oss.sonatype.org/content/repositories/snapshots/"
}

def getRepositoryUsername() {
        return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
}

def getRepositoryPassword() {
        return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
}

afterEvaluate { project ->
        uploadArchives {
                repositories {
                        mavenDeployer {
                                beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

                                pom.groupId = GROUP
                                pom.artifactId = POM_ARTIFACT_ID
                                pom.version = VERSION_NAME

                                repository(url: getReleaseRepositoryUrl()) {
                                        authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
                                }
                                snapshotRepository(url: getSnapshotRepositoryUrl()) {
                                        authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
                                }

                                pom.project {
                                        name POM_NAME
                                        packaging POM_PACKAGING
                                        description POM_DESCRIPTION
                                        url POM_URL

                                        scm {
                                                url POM_SCM_URL
                                                connection POM_SCM_CONNECTION
                                                developerConnection POM_SCM_DEV_CONNECTION
                                        }

                                        licenses {
                                                license {
                                                        name POM_LICENCE_NAME
                                                        url POM_LICENCE_URL
                                                        distribution POM_LICENCE_DIST
                                                }
                                        }

                                        developers {
                                                developer {
                                                        id POM_DEVELOPER_ID
                                                        name POM_DEVELOPER_NAME
                                                }
                                        }
                                }
                        }
                }
        }

        signing {
                required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
                sign configurations.archives
        }

        task androidSourcesJar(type: Jar) {
                classifier = 'sources'
                from android.sourceSets.main.java.sourceFiles
        }

        artifacts {
                archives androidSourcesJar
        }
}

问题是,当我运行时./gradlew :mylibrary:uploadArchives,它会在其中创建一个mylibrary-1.0.aar文件mylibrary/build/outputs/aar/并上传该文件。问题是它没有捆绑我的依赖项。

我想以某种方式创建mylibrary-1.0.aar捆绑了我的所有依赖项,然后将其上传。不幸的是,我对我使用的上传代码的工作原理没有完全清楚的了解。有谁知道我怎样才能做我想做的事?

4

0 回答 0