Artifactory的发布与资源的Andr​​oid库 [英] Artifactory Publish Android Library with Resources

查看:380
本文介绍了Artifactory的发布与资源的Andr​​oid库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

我想创建一个可以使用包含在一个应用程序在Android库:

  //应用程序的的build.gradle
编译com.mycompany:在MyLibrary:1.0.0

在我的情况下,我使用的 Artifactory的,我已经得到了上面的做工精细。问题是,当我尝试运行应用程序我缺少的资源。这个问题似乎是我的图书馆有code取决于它们没有得到包括在发布到罐子资源 Artifactory的

在库

  // code,抛出异常,因为<资源>不包括在所述罐
的getString(R.string<资源>)


问:

我怎样才能包括在罐子里的资源发布到 Artifactory的时候?目前,它仅包括类文件。这是我目前的gradle.build用于发布:

  // Android的图书​​馆 - 的build.gradle
{
    // ...其他的build.gradle设置何去何从    // ================================================ ==========
    // Artifactory的设置
    // ================================================ ==========    buildscript {
        库{
            行家{
                网址$ {} artifactory_contextUrl /插件释放
                凭据{
                    用户名=$ {} artifactory_user
                    密码=$ {} artifactory_password
                }
            }
        }
        依赖{
            类路径org.jfrog.buildinfo:建设 - 信息 - 提取 - gradle这个:3.0.3
        }
    }    应用插件:com.jfrog.artifactory
    应用插件:'Maven的发布    Artifactory的{
        contextUrl =$ {} artifactory_contextUrl
        发布{
            库{
                repoKey ='库释放本地
                用户名=$ {} artifactory_user
                密码=$ {} artifactory_password
                行家=真
            }
            默认{
                出版物('mavenJava')
            }
        }
        解决{
            库{
                repoKey ='库释放
                用户名=$ {} artifactory_user
                密码=$ {} artifactory_password
                行家=真
            }
        }
    }    任务sourceJar(类型:罐){
        从android.sourceSets.main.java.srcDirs
    }    出版{
        出版物{
            mavenJava(MavenPublication){
                的groupId'com.mycompany
                artifactId的在MyLibrary
                版本1.0.0
                神器(sourceJar)
            }
        }
    }
}


解决方案

我能解决我的问题。我发现我的解决方案<一个href=\"http://newscentral.exsees.com/item/6ededc236fe4a68bda28f9aa26e9d0f8-bde760935356551ee8d522debba080e5\"相对=nofollow>这里和<一个href=\"https://github.com/JFrogDev/project-examples/blob/master/gradle-examples/gradle-android-aar/build.gradle\"相对=nofollow>这里。

我原来的 gradle.build 剧本罚款发布jar文件;然而,构建一个Android库与其他项目使用的时候,你通常需要一个 .aar 文件,不是一个.jar 文件。


为了有Artifactory的发布 .aar 文件,我在下面抄我的build.gradle。

注意:您必须使用 com.android.library 插件,否则你会落得个 .apk文件代替 .aar

 应用插件:'com.android.library安卓{
    // ... Android的具体参数
}依赖{
    // ... Android的具体依赖
}// ================================================ ==========
// Artifactory的设置
// ================================================ ==========buildscript {
    库{
        行家{
            网址$ {} artifactory_contextUrl /插件释放
            凭据{
                用户名=$ {} artifactory_user
                密码=$ {} artifactory_password
            }
        }
    }
    依赖{
        类路径'com.github.dcendents:Android的Maven的插件:1.2
        类路径'org.jfrog.buildinfo:建设 - 信息 - 提取 - gradle这个:2.2.3
    }
}应用插件:'artifactory的
应用插件:'com.github.dcendents.android-行家版本=1.0.0
组=com.mycompany配置{
    发表
}任务sourceJar(类型:罐){
    从android.sourceSets.main.java.srcDirs
}artifactoryPublish {
    dependsOn sourceJar
}文物{
    发表sourceJar
}Artifactory的{
    contextUrl =$ {} artifactory_contextUrl
    发布{
        库{
            repoKey ='库释放本地
            用户名=$ {} artifactory_user
            密码=$ {} artifactory_password
            行家=真
        }
        默认{
            publishConfigs('档案','出版')
            性能= ['build.status':'整合']
            publishPom =真
            publishIvy = FALSE
        }
    }
}

Problem:

I am trying to create an Android Library which can be included in an application using:

// Application's build.gradle
compile 'com.mycompany:mylibrary:1.0.0'

In my case, I am using Artifactory and I have gotten the above to work fine. The problem is when I try to run the application I a missing resources. The problem seems to be that my library has code that depends on resources which are not getting included in the jar published to Artifactory

// Code in library, throws exception because <resource> is not included in the jar
getString(R.string.<resource>)


Question:

How can I include the resources in the jar when publishing to Artifactory? Currently, it only includes the class files. Here is my current gradle.build for publishing:

// 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)
            }
        }
    }
}

解决方案

I was able to fix my issue. I found my solution here and here.

My original gradle.build script was fine for publishing jar files; however, when building an android library for use with other projects you typically want a .aar file, not a .jar file.


In order to have Artifactory publish a .aar file I've copied my build.gradle below.

NOTE: you must use the com.android.library plugin otherwise you'll end up with a .apk instead of a .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
        }
    }
}

这篇关于Artifactory的发布与资源的Andr​​oid库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆