如何将 Android .aar 文件发布到 Artifactory
How to publish an Android .aar file to Artifactory
我有一个名为 "myLibAndroid" 的 Android.aar 项目。目录结构有一个根级 "build.gradle" 文件和一个名为 "library" 的子目录,该子目录还包含一个 "build.gradle" 文件。 .aar 文件构建良好但无法发布到 Artifactory。
这是我的顶级 "build.gradle" 文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.0.0'
}
}
allprojects {
repositories {
jcenter()
maven {
url 'http://artifactory.mycompany.local/artifactory/libs-releases-local'
}
}
}
这是 "library" 目录中的 "build.gradle" 文件:
apply plugin: 'com.android.library'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
def packageName = 'com.mycompany.myLib.myLibAndroid'
def libraryVersion = '0.0.1'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 22
versionCode 1
versionName libraryVersion
setProperty("archivesBaseName", "myLibAndroid-$libraryVersion")
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
publishing {
publications {
aar(MavenPublication) {
groupId packageName
version = libraryVersion
// artifactId project.getName()
artifactId "$archivesBaseName"
// artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
artifact("$buildDir/outputs/aar/$archivesBaseName-release.aar")
}
}
}
artifactory {
contextUrl = 'http://artifactory.mycompany.local/artifactory'
publish {
repository {
repoKey = libraryVersion.endsWith('SNAPSHOT') ? 'libs-snapshot-local' : 'libs-release-local'
username = artifactory_username
password = artifactory_password
}
defaults {
publishArtifacts = true
publications('aar')
// Properties to be attached to the published artifacts.
properties = ['qa.level': 'basic', 'dev.team': 'core']
// Publishes everything by default so just turn off what's not desired
publishIvy = false
// Is this even necessary since it's TRUE by default?
// Publish generated POM files to Artifactory (true by default)
publishPom = true
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
}
tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }
task copyNativeLibs(type: Copy) {
from '../../libs/android'
include '**/*.so'
into 'src/main/jniLibs'
}
clean.dependsOn 'cleanCopyNativeLibs'
以下是 "gradlew artifactoryPublish" 的结果:
[buildinfo] Not using buildInfo properties file for this build.
:library:generatePomFileForAarPublication
:library:artifactoryPublish
Deploying artifact: http://artifactory.mycompany.local/artifactory/libs-release-local/com/mycompay/myLib/myLibAndroid/myLibAndroid-0.0.1/0.0.1/myLibAndroid-0.0.1-0.0.1.aar
:library:artifactoryPublish FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':library:artifactoryPublish'.
> java.net.SocketException: Connection reset by peer: socket write error
BUILD FAILED
Total time: 5.71 secs
注意:我想要的 deploy/publish URL 与我们的 Artifactory 当前发布内容的方式相匹配:
http://artifactory.mycompany.local/artifactory/libs-release-local/com/mycompay/myLib/myLibAndroid/0.0.1/myLibAndroid-0.0.1.aar
第一个问题是修复工件 URL,它有多个与版本号相关的错误。第二个问题是导致 Java SocketException.
的原因
这些 Gradle 文件似乎接近正常工作,所以希望一两个小的改变就能解决问题?
好的,我解决了第一个问题——正确构建 Artifactory URL。以下是 "library" 目录中 "build.gradle" 的更改(从上到下),使其正常工作:
def packageName = 'com.mycompany.myLib'
// Replace first line with second line under "defaultConfig"
setProperty("archivesBaseName", "myLibAndroid-$libraryVersion")
archivesBaseName = "myLibAndroid"
但是套接字写入错误仍然存在。那个人是个笨蛋。我可以手动上传到相同的 Artifactory 位置。
很可能,套接字错误是由于不正确的 Artifactory 登录凭据 and/or 权限造成的。您是否尝试过检查 Artifactory 访问日志?我看到有人输入错误的用户名也是如此。
<artifactory_url>/webapp/#/admin/advanced/system_logs -> access.log
2016-05-10 13:12:52,252 [DENIED LOGIN] for user@work.com/xxx.xx.xx.xx.
...
我没有看到您在构建脚本中设置 artifactory_username
和 artifactory_password
的任何地方。
username = artifactory_username
password = artifactory_password
这些实际上需要是字符串值。来自 Gradle Artifactory Plugin doc
username = 'resolver' //Optional resolver user name (leave out to use anonymous resolution)
password = 'resolverPaS*' //The resolver password
我喜欢在这里使用类似 属性 的东西,这可能是您想要做的。像这样:
username = project.hasProperty('repositoryUser') ? repositoryUser : ''
password = project.hasProperty('repositoryPassword') ? repositoryPassword : ''
我有一个名为 "myLibAndroid" 的 Android.aar 项目。目录结构有一个根级 "build.gradle" 文件和一个名为 "library" 的子目录,该子目录还包含一个 "build.gradle" 文件。 .aar 文件构建良好但无法发布到 Artifactory。
这是我的顶级 "build.gradle" 文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.0.0'
}
}
allprojects {
repositories {
jcenter()
maven {
url 'http://artifactory.mycompany.local/artifactory/libs-releases-local'
}
}
}
这是 "library" 目录中的 "build.gradle" 文件:
apply plugin: 'com.android.library'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
def packageName = 'com.mycompany.myLib.myLibAndroid'
def libraryVersion = '0.0.1'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 22
versionCode 1
versionName libraryVersion
setProperty("archivesBaseName", "myLibAndroid-$libraryVersion")
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
publishing {
publications {
aar(MavenPublication) {
groupId packageName
version = libraryVersion
// artifactId project.getName()
artifactId "$archivesBaseName"
// artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
artifact("$buildDir/outputs/aar/$archivesBaseName-release.aar")
}
}
}
artifactory {
contextUrl = 'http://artifactory.mycompany.local/artifactory'
publish {
repository {
repoKey = libraryVersion.endsWith('SNAPSHOT') ? 'libs-snapshot-local' : 'libs-release-local'
username = artifactory_username
password = artifactory_password
}
defaults {
publishArtifacts = true
publications('aar')
// Properties to be attached to the published artifacts.
properties = ['qa.level': 'basic', 'dev.team': 'core']
// Publishes everything by default so just turn off what's not desired
publishIvy = false
// Is this even necessary since it's TRUE by default?
// Publish generated POM files to Artifactory (true by default)
publishPom = true
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
}
tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }
task copyNativeLibs(type: Copy) {
from '../../libs/android'
include '**/*.so'
into 'src/main/jniLibs'
}
clean.dependsOn 'cleanCopyNativeLibs'
以下是 "gradlew artifactoryPublish" 的结果:
[buildinfo] Not using buildInfo properties file for this build.
:library:generatePomFileForAarPublication
:library:artifactoryPublish
Deploying artifact: http://artifactory.mycompany.local/artifactory/libs-release-local/com/mycompay/myLib/myLibAndroid/myLibAndroid-0.0.1/0.0.1/myLibAndroid-0.0.1-0.0.1.aar
:library:artifactoryPublish FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':library:artifactoryPublish'.
> java.net.SocketException: Connection reset by peer: socket write error
BUILD FAILED
Total time: 5.71 secs
注意:我想要的 deploy/publish URL 与我们的 Artifactory 当前发布内容的方式相匹配:
http://artifactory.mycompany.local/artifactory/libs-release-local/com/mycompay/myLib/myLibAndroid/0.0.1/myLibAndroid-0.0.1.aar
第一个问题是修复工件 URL,它有多个与版本号相关的错误。第二个问题是导致 Java SocketException.
的原因这些 Gradle 文件似乎接近正常工作,所以希望一两个小的改变就能解决问题?
好的,我解决了第一个问题——正确构建 Artifactory URL。以下是 "library" 目录中 "build.gradle" 的更改(从上到下),使其正常工作:
def packageName = 'com.mycompany.myLib'
// Replace first line with second line under "defaultConfig"
setProperty("archivesBaseName", "myLibAndroid-$libraryVersion")
archivesBaseName = "myLibAndroid"
但是套接字写入错误仍然存在。那个人是个笨蛋。我可以手动上传到相同的 Artifactory 位置。
很可能,套接字错误是由于不正确的 Artifactory 登录凭据 and/or 权限造成的。您是否尝试过检查 Artifactory 访问日志?我看到有人输入错误的用户名也是如此。
<artifactory_url>/webapp/#/admin/advanced/system_logs -> access.log
2016-05-10 13:12:52,252 [DENIED LOGIN] for user@work.com/xxx.xx.xx.xx.
...
我没有看到您在构建脚本中设置 artifactory_username
和 artifactory_password
的任何地方。
username = artifactory_username
password = artifactory_password
这些实际上需要是字符串值。来自 Gradle Artifactory Plugin doc
username = 'resolver' //Optional resolver user name (leave out to use anonymous resolution)
password = 'resolverPaS*' //The resolver password
我喜欢在这里使用类似 属性 的东西,这可能是您想要做的。像这样:
username = project.hasProperty('repositoryUser') ? repositoryUser : ''
password = project.hasProperty('repositoryPassword') ? repositoryPassword : ''