一尘不染

Android Library Gradle版本JAR

java

如何发布android-library项目的Jar包装?
我发现,classes.jar位于下面build/bundles/release/classes.jar,我想这是正确的Jar包(包含*.class文件)。

有什么正式的方法可以将库发布为JAR而不是AAR?

编辑
我使用Gradle发行了Maven构件,并且我想连同AAR软件包一起发行JAR。因此具有签名,md5,清单…
的JAR 基于https://chris.banes.me/2013/08/27/pushing-aars-to-maven-central/

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

configurations {
    archives {
        extendsFrom configurations.default
    }
}

def sonatypeRepositoryUrl
if (isReleaseBuild()) {
    println 'RELEASE BUILD'
    sonatypeRepositoryUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
} else {
    println 'DEBUG BUILD'
    sonatypeRepositoryUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
}

if(!hasProperty('nexusPassword')) {
    ext.set('nexusPassword', System.console().readPassword("\n\$ Type in password for Sonatype nexus account " + nexusUsername + ": "))
}

if(!signing.hasProperty('password')) {
    ext.set('signing.password', System.console().readPassword("\n\$ Type in GPG key password: "))
}

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

                pom.artifactId = POM_ARTIFACT_ID

                repository(url: sonatypeRepositoryUrl) {
                    authentication(userName: nexusUsername, password: nexusPassword)
                }

                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 "loopj"
                            name "James Smith"
                        }
                        developer {
                            id "smarek"
                            name "Marek Sebera"
                        }
                    }
                }
            }
        }
    }

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

    task androidJavadocs(type: Javadoc) {
        source = android.sourceSets.main.java.srcDirs
    }

    task androidJavadocsJar(type: Jar) {
        classifier = 'javadoc'
        from androidJavadocs.destinationDir
    }

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

    artifacts {
        archives androidSourcesJar
        archives androidJavadocsJar
    }
}

使用

task androidJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
}

将仅打包Java文件,而不打包并针对android sdk链接


阅读 348

收藏
2020-03-23

共1个答案

一尘不染

虽然我还没有尝试将带有部署的工件上传到Sonatype(甚至本地存储库),但几周前,当我试图解决相同的问题时,我还是想出了这点。

android.libraryVariants.all { variant ->
  def name = variant.buildType.name
  if (name.equals(com.android.builder.core.BuilderConstants.DEBUG)) {
    return; // Skip debug builds.
  }
  def task = project.tasks.create "jar${name.capitalize()}", Jar
  task.dependsOn variant.javaCompile
  task.from variant.javaCompile.destinationDir
  artifacts.add('archives', task);
}

然后运行以下命令:

./gradlew jarRelease
2020-03-23