本文主要是介绍把Android library分享到jCenter的方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
如果你想在Android Studio中使用如下方法,引入一个library:
- dependencies {
- compile 'com.inthecheesefactory.thecheeselibrary:fb-like:0.9.3'
- }
-
- jcenter是一个由 bintray.com维护的Maven仓库,那么
- 1.注册bintray.com
- 2.添加一个maven库(repository)
- 3.在新建的maven库中创建一个package(包名字母应该为小写,单词之间用-分割,比如,common-util)
- 4.编辑project的build.gradle
-
dependencies {classpath 'com.android.tools.build:gradle:2.1.0' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }
-
5.编辑要分享到jcenter的module的build.gradle,添加以下内容
-
apply plugin: 'com.android.library' apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray' version = "1.0.0" def siteUrl = 'https://github.com/crisHill/common_util' // 项目在github上的主页 def gitUrl = 'https://github.com/crisHill/common_util.git' // Git仓库的url
group = "zls.android"
// 第三方引用这里所分享的library时的格式是 compile 'group:your module name:version'// 这里对应的格式是 compile 'zls.android:commonutil:1.0.0' -
install {repositories.mavenInstaller {// This generates POM.xml with proper parameters pom {project {packaging 'aar' name 'Common Util for Android project'//项目描述 url siteUrllicenses {license {name 'The Apache Software License, Version 2.0' url 'http://www.apache.org/licenses/LICENSE-2.0.txt' }}developers {developer {id 'XXX' // 这里的id,name和email可以随便填 name 'YYYYY' email 'ZZZZZ@AA.com' }}scm {connection gitUrldeveloperConnection gitUrlurl siteUrl}}}} } task sourcesJar(type: Jar) {from android.sourceSets.main.java.srcDirsclassifier = 'sources' }task javadoc(type: Javadoc) {source = android.sourceSets.main.java.srcDirsclasspath += project.files(android.getBootClasspath().join(File.pathSeparator)) }task javadocJar(type: Jar, dependsOn: javadoc) {classifier = 'javadoc' from javadoc.destinationDir }artifacts {archives javadocJararchives sourcesJar } bintray {user = "criscris" key = "a71df93f67eec11e0cc94c0f5e701125032d2b0d"
// 有的文章建议把user和key放到local.properties文件中保存,但是这样实际上可能导致gradle无法成功build
configurations = ['archives'] pkg { repo = "maven" // 刚刚在bintray创建的maven库的名字
name = "common_util" // 刚刚创建的maven库的package的名字 websiteUrl = siteUrl vcsUrl = gitUrl licenses = ["Apache-2.0"] publish = true }} -
6.点击Android studio右侧的gradle,打开gradle project
-
依次进入 :modulename / Tasks / publishing / bintrayUpload,双击bintrayUpload上传
-
7.点击 Add to JCenter,在打开的页面直接点击 Send,向bintray请求把发布的maven package添加到jcenter
-
-
8.如果收到了通过审核的邮件,则可以在Android studio中直接引用以上发布的library
-
compile 'zls.android:commonutil:1.0.1'
更加详细的内容,参考:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0623/3097.html
这篇关于把Android library分享到jCenter的方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!