gpt4 book ai didi

android - 如何使用 artifactoryPublish 发布发布和调试 Artifact

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:23:00 35 4
gpt4 key购买 nike

我的 Android Studio 项目可以在发布版和调试版中构建 AAR 或 APK。我想将这些发布到我的 Artifactory 服务器上不同的存储库。 JFrog examples似乎没有涵盖这种情况。

这是否意味着仅构建发布版本或仅构建调试版本并根据构建类型选择上传内容和上传位置被认为是最佳实践?

最佳答案

我配置了我的 android 库 build.gradle 文件,编译后的 aar 文件可以上传到不同的 repos,具体取决于构建类型。
例如,您想将调试 Artifact 发布到“libs-debug-local”存储库,并将 Artifact 发布到“libs-release-local”存储库。

//First you should configure all artifacts you want to publish
publishing {
publications {

//Iterate all build types to make specific
//artifact for every build type
android.buildTypes.all { variant ->

//it will create different
//publications ('debugAar' and 'releaseAar')
"${variant.name}Aar"(MavenPublication) {
def manifestParser = new com.android.builder.core.DefaultManifestParser()

//Set values from Android manifest file
groupId manifestParser.getPackage(android.sourceSets.main.manifest.srcFile)
version = manifestParser.getVersionName(android.sourceSets.main.manifest.srcFile)
artifactId project.getName()

// Tell maven to prepare the generated "*.aar" file for publishing
artifact("$buildDir/outputs/aar/${project.getName()}-${variant.name}.aar")
}
}
}
}

//After configuring publications you should
//create tasks to set correct repo key
android.buildTypes.all { variant ->

//same publication name as we created above
def publicationName = "${variant.name}Aar"

//new task name
def taskName = "${variant.name}Publication"

//in execution time setting publications and repo key, dependent on build type
tasks."$taskName" << {
artifactoryPublish {
doFirst {
publications(publicationName)
clientConfig.publisher.repoKey = "libs-${variant.name}-local"
}
}
}

//make tasks assembleDebug and assembleRelease dependent on our new tasks
//it helps to set corrent values for every task
tasks."assemble${variant.name.capitalize()}".dependsOn(tasks."$taskName")
}

//Inside artifactory block just set url and credential, without setting repo key and publications
artifactory {
contextUrl = 'http://artifactory.cooperok.com:8081/artifactory'
publish {
repository {
username = "username"
password = "password"
}
defaults {
publishArtifacts = true

// Properties to be attached to the published artifacts.
properties = ['qa.level': 'basic', 'dev.team': 'core']
}
}
}

就是这样。现在,如果你运行命令

Win : gradlew assembleRelease artifactoryPublish Mac:./gradlew assembleRelease artifactoryPublish

aar 文件将上传到“libs-release-local”存储库。
如果你跑了

Win : gradlew assembleDebug artifactoryPublish Mac:./gradlew assembleDebug artifactoryPublish

它将被上传到'libs-debug-local' 仓库

此配置的一个缺点是您应该始终使用 assembleDebug/Release 任务运行 artifactoryPublish 任务

关于android - 如何使用 artifactoryPublish 发布发布和调试 Artifact ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31949919/

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