gpt4 book ai didi

android - 在Gradle无法正常工作的情况下将AAR文件发布到Maven Central

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:57:12 26 4
gpt4 key购买 nike

,在Gradle仍然无法正常工作的情况下,将aar文件发布到Maven Central:

好的,让我们重复我为“使用Gradle将aar文件发布到Maven Central”(我主要遵循此guide)而设法完成的所有步骤,只是为了确保...

1)我使用“Android Studio”,我有一个想要在maven上可用的简单android lib:https://github.com/danielemaddaluno/Android-Update-Checker

2)在UpdateCheckerLib文件夹中,我具有上述的lib代码。并在此文件夹apply plugin: 'com.android.library'的build.gradle中应用我作为输出的.aar在模块目录的build/outputs/aar/目录中

3)我的第一步是找到一个批准的存储库。我决定使用Sonatype OSS Repository。在这里,我注册了一个项目,并使用groupid com.github.danielemaddaluno注册了一个新期(创建->创建期->社区支持-开源项目存储库托管->新项目)。

4)因此,我在项目的根目录中添加了一个文件:maven_push.gradle:

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

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

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

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

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

pom.artifactId = POM_ARTIFACT_ID

repository(url: sonatypeRepositoryUrl) {
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 androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.sourceFiles
}

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

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

artifacts {
//archives packageReleaseJar
archives androidSourcesJar
archives androidJavadocsJar
}
}

6)我在根目录下的gradle.properties文件中添加了以下几行:
VERSION_NAME=1.0.1-SNAPSHOT
VERSION_CODE=2
GROUP=com.github.danielemaddaluno

POM_DESCRIPTION=Android Update Checker
POM_URL=https://github.com/danielemaddaluno/Android-Update-Checker
POM_SCM_URL=https://github.com/danielemaddaluno/Android-Update-Checker
POM_SCM_CONNECTION=scm:git@github.com:danielemaddaluno/Android-Update-Checker.git
POM_SCM_DEV_CONNECTION=scm:git@github.com:danielemaddaluno/Android-Update-Checker.git
POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=danielemaddaluno
POM_DEVELOPER_NAME=Daniele Maddaluno

7)在根目录下,我从下面修改了build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}

allprojects {
repositories {
jcenter()
}
}

对此:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}

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

allprojects {
version = VERSION_NAME
group = GROUP

repositories {
mavenCentral()
}
}

apply plugin: 'android-reporting'

8)我读到对于要上传到Central的每个模块或应用程序,我应该:
  • 提供一个gradle.properties
  • 修改build.gradle在末尾添加以下行:apply from: '../maven_push.gradle'

  • 因此,在UpdateCheckerLib文件夹中,我:
  • 添加了gradle.properties:
    POM_NAME=Android Update Checker
    POM_ARTIFACT_ID=androidupdatechecker
    POM_PACKAGING=aar
  • 修改了build.gradle,在文件底部添加了以下行:apply from: '../maven_push.gradle'

  • 9)为了对我的文物进行签名,我做了以下操作:
    gpg --gen-key
    gpg --list-keys --> get my PubKeyId...
    gpg --keyserver hkp://pool.sks-keyservers.net --send-keys PubKeyId

    10)我向 ~/.gradle/gradle.properties路径添加了一个文件,其内容如下所示(要获取我使用 gpg --list-secret-keys的 key ):
    signing.keyId=xxxxxxx
    signing.password=YourPublicKeyPassword
    signing.secretKeyRingFile=~/.gnupg/secring.gpg

    nexusUsername=YourSonatypeJiraUsername
    nexusPassword=YourSonatypeJiraPassword

    11)终端中的 sudo apt-get install gradle,因为“Andoid Studio”终端无法识别gradle ...

    12)最后 gradle uploadArchives
    13)我收到此错误:
    FAILURE: Build failed with an exception.

    * Where:
    Build file '/home/madx/Documents/Workspace/Android-Update-Checker/UpdateCheckerLib/build.gradle' line: 1

    * What went wrong:
    A problem occurred evaluating project ':UpdateCheckerLib'.
    > Could not create plugin of type 'LibraryPlugin'.

    可能仅仅是由于gradle/gradle插件问题引起的,但是我想分享所有过程,以防万一它可能对其他人有帮助!

    提前致谢!

    ,在Gradle仍然无法正常工作的情况下,将aar文件发布到jCenter:

    非常感谢JBaruch和他的助手!因此,我尝试将其发布到jCenter而不是Maven Central,实际上jcenter()是mavenCentral()的超集。
    好吧,让我们从我的github库 Android-Update-Checker再次开始。
    我试图遵循他的一些技巧,但我仍然陷于困境...
    我还将为jcenter发布编写步骤(希望对某人有用)。也许我在想什么...

    1)使用 username注册到Bintray:danielemaddaluno

    2)启用上传内容的自动签名:
    从Bintray profile url-> GPG签名->复制粘贴您的 public/private keys。您可以在文件 public_key_sender.asc/private_key_sender.asc中分别找到这两个
    如果执行以下代码( -a中的 --armorgpg选项用于生成ASCII铠装 key 对):
        gpg --gen-key
    gpg -a --export daniele.maddaluno@gmail.com > public_key_sender.asc
    gpg -a --export-secret-key daniele.maddaluno@gmail.com > private_key_sender.asc

    2.1)在同一个 web page中,您可以从以下位置配置自动签名:存储库-> Maven->选中“GPG自动对上传的文件签名”->更新

    3)在同一个 web page中,您可以找到自己的 Bintray API Key(将其复制以备后用)

    4)在同一 web page中,您可以配置 Sonatype OSS User(在问题的上一部分中,我已经创建了一个用户和一个问题)

    5)我将这两行添加到根目录中的 build.gradle
    classpath 'com.github.dcendents:android-maven-plugin:1.2'
    classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.1"

    这样我在根目录中的自己的 build.gradle看起来像:
    buildscript {
    repositories {
    jcenter()
    }
    dependencies {
    classpath 'com.android.tools.build:gradle:1.0.0'
    classpath 'com.github.dcendents:android-maven-plugin:1.2'
    classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.1"
    }
    }

    allprojects {
    repositories {
    jcenter()
    }
    }

    6)我修改了位于项目文件夹中的 build.gradle,它看起来像:
    apply plugin: 'com.android.library'
    apply plugin: 'com.github.dcendents.android-maven'
    apply plugin: "com.jfrog.bintray"

    // This is the library version used when deploying the artifact
    version = "1.0.0"

    android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
    //applicationId "com.madx.updatechecker.lib"
    minSdkVersion 8
    targetSdkVersion 21
    versionCode 1
    versionName "1.0.0"
    }
    buildTypes {
    release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    }
    }

    dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'org.jsoup:jsoup:1.8.1'
    }


    def siteUrl = 'https://github.com/danielemaddaluno/Android-Update-Checker' // Homepage URL of the library
    def gitUrl = 'https://github.com/danielemaddaluno/Android-Update-Checker.git' // Git repository URL
    group = "com.github.danielemaddaluno.androidupdatechecker" // Maven Group ID for the artifact


    install {
    repositories.mavenInstaller {
    // This generates POM.xml with proper parameters
    pom {
    project {
    packaging 'aar'

    // Add your description here
    name 'The project aims to provide a reusable instrument to check asynchronously if exists any newer released update of your app on the Store.'
    url siteUrl

    // Set your license
    licenses {
    license {
    name 'The Apache Software License, Version 2.0'
    url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
    }
    }
    developers {
    developer {
    id 'danielemaddaluno'
    name 'Daniele Maddaluno'
    email 'daniele.maddaluno@gmail.com'
    }
    }
    scm {
    connection gitUrl
    developerConnection gitUrl
    url siteUrl

    }
    }
    }
    }
    }

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

    task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    }

    task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
    }
    artifacts {
    archives javadocJar
    archives sourcesJar
    }



    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())

    bintray {
    user = properties.getProperty("bintray.user")
    key = properties.getProperty("bintray.apikey")

    configurations = ['archives']
    pkg {
    repo = "maven"
    name = "androidupdatechecker"
    websiteUrl = siteUrl
    vcsUrl = gitUrl
    licenses = ["Apache-2.0"]
    publish = true
    }
    }

    7)我在根 local.properties文件中添加了以下几行:
    bintray.user=<your bintray username>
    bintray.apikey=<your bintray API key>

    8)在我的PATH中添加了“Android Studio”实际使用的默认gradle 2.2.1,例如:
    PATH=$PATH:/etc/android-studio/gradle/gradle-2.2.1/bin

    9)打开“Android Studio”终端并执行:
    gradle bintrayUpload

    10)从Bintray->我的最新软件包-> androidupdatechecker(仅在执行上一点之后才在这里9)->添加到Jcenter->选中框->组ID =“com.github .danielemaddaluno.androidupdatechecker”。

    11)最后,我尝试遵循:Bintray->我的最新软件包-> androidupdatechecker-> Maven Central->同步,但是在页面右侧的“同步状态”栏中出现此错误:
    Last Synced: Never
    Last Sync Status: Validation Failed
    Last Sync Errors:
    Missing Signature:
    '/com/github/danielemaddaluno/androidupdatechecker/UpdateCheckerLib/1.0.0/UpdateCheckerLib-1.0.0-javadoc.jar.asc'
    does not exist for 'UpdateCheckerLib-1.0.0-javadoc.jar'.
    Missing Signature:
    '/com/github/danielemaddaluno/androidupdatechecker/UpdateCheckerLib/1.0.0/UpdateCheckerLib-1.0.0.aar.asc'
    does not exist for 'UpdateCheckerLib-1.0.0.aar'.
    Missing Signature:
    '/com/github/danielemaddaluno/androidupdatechecker/UpdateCheckerLib/1.0.0/UpdateCheckerLib-1.0.0-sources.jar.asc'
    does not exist for 'UpdateCheckerLib-1.0.0-sources.jar'.
    Missing Signature:
    '/com/github/danielemaddaluno/androidupdatechecker/UpdateCheckerLib/1.0.0/UpdateCheckerLib-1.0.0.pom.asc'
    does not exist for 'UpdateCheckerLib-1.0.0.pom'.
    Invalid POM: /com/github/danielemaddaluno/androidupdatechecker/UpdateCheckerLib/1.0.0/UpdateCheckerLib-1.0.0.pom:
    Project description missing Dropping existing partial staging repository.

    最佳答案

    您可以改为将Aar发布到JCenter。

  • 这是default in Android Studio
  • 您可以sync to Central from there in much easier way
  • 这是so much easier to publish there
  • 您可以使用oss.jfrog.org for snapshots
  • 关于android - 在Gradle无法正常工作的情况下将AAR文件发布到Maven Central,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28383415/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com