Artifactory Publish Android 资源库
Artifactory Publish Android Library with Resources
问题:
我正在尝试创建一个 Android 库,它可以包含在一个应用程序中,使用:
// Application's build.gradle
compile 'com.mycompany:mylibrary:1.0.0'
在我的例子中,我使用的是 Artifactory 并且我已经使上述工作正常。问题是当我尝试 运行 缺少资源的应用程序时。问题似乎是我的库有依赖于资源的代码,这些资源没有包含在发布到 Artifactory
的 jar 中
// Code in library, throws exception because <resource> is not included in the jar
getString(R.string.<resource>)
问题:
发布到 Artifactory 时如何将资源包含在 jar 中?目前,它仅包含 class 个文件。这是我目前要发布的 gradle.build:
// Android Library - build.gradle
{
// ... Other build.gradle settings go here
//==========================================================
// ARTIFACTORY SETTINGS
//==========================================================
buildscript {
repositories {
maven {
url "${artifactory_contextUrl}/plugins-release"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.3"
}
}
apply plugin: "com.jfrog.artifactory"
apply plugin: 'maven-publish'
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'libs-release-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
defaults {
publications ('mavenJava')
}
}
resolve {
repository {
repoKey = 'libs-release'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
task sourceJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId 'com.mycompany'
artifactId 'mylibrary'
version '1.0.0'
artifact(sourceJar)
}
}
}
}
我能够解决我的问题。我找到了我的解决方案 here and here.
我原来的 gradle.build
脚本可以很好地发布 jar 文件;但是,在构建用于其他项目的 android 库时,您通常需要 .aar 文件, 而不是 .jar 文件。
为了让 Artifactory 发布一个 .aar 文件,我在下面复制了我的 build.gradle。
注意: 您必须使用 com.android.library
插件,否则您将得到 .apk 而不是.aar.
apply plugin: 'com.android.library'
android {
//... Android specific parameters
}
dependencies {
//... Android specific dependencies
}
//==========================================================
// ARTIFACTORY SETTINGS
//==========================================================
buildscript {
repositories {
maven {
url "${artifactory_contextUrl}/plugins-release"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
dependencies {
classpath 'com.github.dcendents:android-maven-plugin:1.2'
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:2.2.3'
}
}
apply plugin: 'artifactory'
apply plugin: 'com.github.dcendents.android-maven'
version = "1.0.0"
group = "com.mycompany"
configurations {
published
}
task sourceJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
}
artifactoryPublish {
dependsOn sourceJar
}
artifacts {
published sourceJar
}
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'libs-release-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
defaults {
publishConfigs('archives', 'published')
properties = ['build.status': 'integration']
publishPom = true
publishIvy = false
}
}
}
问题:
我正在尝试创建一个 Android 库,它可以包含在一个应用程序中,使用:
// Application's build.gradle
compile 'com.mycompany:mylibrary:1.0.0'
在我的例子中,我使用的是 Artifactory 并且我已经使上述工作正常。问题是当我尝试 运行 缺少资源的应用程序时。问题似乎是我的库有依赖于资源的代码,这些资源没有包含在发布到 Artifactory
的 jar 中// Code in library, throws exception because <resource> is not included in the jar
getString(R.string.<resource>)
问题:
发布到 Artifactory 时如何将资源包含在 jar 中?目前,它仅包含 class 个文件。这是我目前要发布的 gradle.build:
// Android Library - build.gradle
{
// ... Other build.gradle settings go here
//==========================================================
// ARTIFACTORY SETTINGS
//==========================================================
buildscript {
repositories {
maven {
url "${artifactory_contextUrl}/plugins-release"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.3"
}
}
apply plugin: "com.jfrog.artifactory"
apply plugin: 'maven-publish'
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'libs-release-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
defaults {
publications ('mavenJava')
}
}
resolve {
repository {
repoKey = 'libs-release'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
task sourceJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId 'com.mycompany'
artifactId 'mylibrary'
version '1.0.0'
artifact(sourceJar)
}
}
}
}
我能够解决我的问题。我找到了我的解决方案 here and here.
我原来的 gradle.build
脚本可以很好地发布 jar 文件;但是,在构建用于其他项目的 android 库时,您通常需要 .aar 文件, 而不是 .jar 文件。
为了让 Artifactory 发布一个 .aar 文件,我在下面复制了我的 build.gradle。
注意: 您必须使用 com.android.library
插件,否则您将得到 .apk 而不是.aar.
apply plugin: 'com.android.library'
android {
//... Android specific parameters
}
dependencies {
//... Android specific dependencies
}
//==========================================================
// ARTIFACTORY SETTINGS
//==========================================================
buildscript {
repositories {
maven {
url "${artifactory_contextUrl}/plugins-release"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
dependencies {
classpath 'com.github.dcendents:android-maven-plugin:1.2'
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:2.2.3'
}
}
apply plugin: 'artifactory'
apply plugin: 'com.github.dcendents.android-maven'
version = "1.0.0"
group = "com.mycompany"
configurations {
published
}
task sourceJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
}
artifactoryPublish {
dependsOn sourceJar
}
artifacts {
published sourceJar
}
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'libs-release-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
defaults {
publishConfigs('archives', 'published')
properties = ['build.status': 'integration']
publishPom = true
publishIvy = false
}
}
}