在 Android Studio 中,我们通常可以利用 gradle 来导入别人写的第三方库,通常可以简单得使用一句话就能搞定整个导包过程,

比如:

compile 'net.cpacm.moneytext:moneyview:1.0.0'

在这个过程中,Android Studio 会从 Maven 仓库服务器中下载所对应的包。现在比较通用的两个服务器分别为 Jcenter 和 Maven Central。本文主要讲的就是Jcenter了,Android Studio 默认使用的服务器仓库。

Jcenter

Jcenter 是 bintray.com 所使用的 Maven 仓库。与 Maven Central 相比,jcenter 的速度更快,包含的库更多,UI界面更友好,更容易使用,同时 bintray 还支持将 jcenter 上传到 Maven Central 的功能。

语法规则

以前使用过 Maven 的可能会比较清楚,导入的语句如何指向仓库中唯一存在的库。

compile 'net.cpacm.simpleslider:library:1.0.0'
compile 'GROUP_ID:ARTIFACT_ID:VERSION'

其中

GROUP_ID 是指包所在的组,比如我包放在 net.cpacm.simpleslider 中, 那么我的 GROUP_ID 就是 net.cpacm.simpleslider

ARTIFACT_ID 是指工程名字,一般在android中都为library

VERSION 代表使用的包的版本。

Bintray 使用

请科学上网

bintray 支持 githubgoogle+ 第三方直接登录。



登录后进入 Maven 仓库建立要使用的包,同时填入相应的对应信息。







Gradle 配置

首先确保你要上传的第三方包是一个 library,作为一个项目的 module 存在。

project gradle

在 project gradle 中加入需要的依赖包

buildscript {
repositories {
jcenter()
}
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.5" }
} allprojects {
repositories {
jcenter()
}
} task clean(type: Delete) {
delete rootProject.buildDir
}

local.properties

在项目的 local.properties 文件里面加入 api-key

bintray.user=YOUR_BINTRAY_USERNAME
bintray.apikey=YOUR_BINTRAY_API_KEY

在 bintray 网站的个人信息编辑页可以找到。



对了,记得不要把 local.properties 传到 github网站上导致个人信息的泄露。

library gradle

修改 library 的 gradle 信息

apply plugin: 'com.android.library'
// add plugin
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray' version = '1.0.0' android {
compileSdkVersion 23
buildToolsVersion "23.0.2" defaultConfig {
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
} dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
} task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
} task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
} task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
} group = 'net.cpacm.simpleslider'
install {
repositories.mavenInstaller {
pom.project {
packaging 'aar'
groupId 'net.cpacm.simpleslider' //自己定义的组名
artifactId 'library' name 'simpleslider'
description 'A simple slider allows you to easily use.'
url 'https://github.com/cpacm/SimpleSlider'
inceptionYear '2016' licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
scm {
connection 'https://github.com/cpacm/SimpleSlider.git'
url 'https://github.com/cpacm/SimpleSlider' }
developers {
developer {
name 'cpacm'
email 'shenliming@gmail.com'
}
}
} }
} // Bintray //获取local.propertes的信息
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream()) bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")
publish = true
configurations = ['archives']
pkg {
//填入 bintray 上对应的 package 信息
repo = 'maven'
name = 'SimpleSlider'
vcsUrl = 'https://github.com/cpacm/SimpleSlider.git'
websiteUrl = 'https://github.com/cpacm/SimpleSlider'
licenses = ['Apache-2.0']
issueTrackerUrl = 'https://github.com/cpacm/SimpleSlider/issues'
publicDownloadNumbers = true
version {
name = '1.0.0'
desc = 'simple slider release'
vcsTag = '1.0.0'
attributes = ['gradle-plugin': 'com.use.less:com.use.less.gradle:gradle-useless-plugin']
}
}
} tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
} task findConventions << {
println project.getConvention()
}

安装和上传

在Android Studio Terminal窗口中运行命令

gradlew install
gradlew bintrayUpload

至此已经打包上传结束,可以回到 bintray 网站看看结果。

添加到Jcenter

点击上图的 Add to jcenter 按钮,向管理员申请添加到 jcenter 仓库,一般等个几小时就能通过。

最后在 https://jcenter.bintray.com 找到自己的库就表示成功了。


作者:cpacm

参考资料:http://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en

地址:将你的代码上传 Bintray 仓库

将你的代码上传 Bintray 仓库的更多相关文章

  1. 将你的代码上传 Bintray 仓库(转)

    转自:http://www.cnblogs.com/cpacm/p/5548241.html 在 Android Studio 中,我们通常可以利用 gradle 来导入别人写的第三方库,通常可以简单 ...

  2. (超详细)使用git命令行将本地仓库代码上传到github或gitlab远程仓库

    (超详细)使用git命令行将本地仓库代码上传到github或gitlab远程仓库 本地创建了一个 xcode 工程项目,现通过 命令行 将该项目上传到 github 或者 gitlab 远程仓库,具体 ...

  3. IDEA新项目代码上传到gitlab远程仓库

    IDEA新项目代码上传到gitlab远程仓库 具体步骤 创建本地仓库 IDEA:VCS-->Import into Version Control-->Create Git Reposit ...

  4. github将本地仓库的代码上传到Github

    本篇主要参考博文:https://blog.csdn.net/IT_faquir/article/details/52516214 你要先完成上一篇的操作,即将代码上传到本地仓库中,才能上传到gith ...

  5. 代码上传多个git仓库,切换过remote后导致 can't update

    问题描述: 因为代码上传到github和coding 切换了 git--> rmote的地址:后来update失败 问题解决: 重新配置git解决:按提示操作就好 git fetch git p ...

  6. git使用之如何将github库下载到本地与如何将代码上传github

    git使用之如何将github库下载到本地与如何将代码上传github ---------------------------------------------------------------- ...

  7. java~gradle构建公用包并上传到仓库

    java~gradle构建公用包并上传到仓库 我们一般会把公用的代码放在一个包里,然后其它 项目可以直接使用,就像你使用第三方包一样! 仓库 存储包的地方叫做仓库,一般可以分为本地仓库和远程仓库,本地 ...

  8. 如何用git将项目代码上传到github

    注册账户以及创建仓库 要想使用github第一步当然是注册github账号了.之后就可以创建仓库了(免费用户只能建公共仓库),Create a New Repository,填好名称后Create,之 ...

  9. mac上将代码上传到github

    前言 有时我们会写一些小程序来学习新的知识,但是完事之后过一段时间可能会忘记,最好的办法就是找到原来的代码看一看.现在可以将代码免费托管到一些网站上,其中最著名的非github莫属了, 今天就把这个过 ...

随机推荐

  1. 【linux】which和whereis

    which和whereis都是查询命令的指令.区别的是: which能查询到命令所在位置: [root@andon tmp]# which ls alias ls='ls --color=auto' ...

  2. HackerRank "Median Updates"

    Same as LintCode "Sliding Window Median", but requires more care on details - no trailing ...

  3. bzoj3319: 黑白树

    Description 给定一棵树,边的颜色为黑或白,初始时全部为白色.维护两个操作:1.查询u到根路径上的第一条黑色边的标号.2.将u到v    路径上的所有边的颜色设为黑色.Notice:这棵树的 ...

  4. java-多态性

    1 多态性 主要表现在上转型对象 2 强制类型转换 2.1 基本类型的强制类型转换 转换只能在数值间进行.包括整数型.字符型.浮点型.数值类型和布尔类型间不能转换. 2.2 引用类型变量转换成其子类型 ...

  5. android学习笔记七——控件(DatePicker、TimePicker、ProgressBar)

    DatePicker.TimePicker ==> DatePicker,用于选择日期 TimePicker,用于选择时间 两者均派生与FrameLayout,两者在FrameLayout的基础 ...

  6. metaspolit教程

    网上的安装方式都是抄来抄去,我也抄了下,不过好歹自己试了下,有所不同 git clone https://github.com/rapid7/metasploit-framework.git vim ...

  7. WINDOWS黑客基础(5):利用内存来进行获取计算结果

    在前面的注入代码的章节中,我们利用了VirtualAllocEx来在对方的进程开辟了一块内存,并且将代码复制进对方进程的内存里面,从而执行那段内存的代码,但是这里有一个问题,就是代码不是执行在我们进程 ...

  8. 从SVN导出指定版本号之间修改的文件

    当一个网站项目进入运营维护阶段以后,不会再频繁地更新全部源文件到服务器,这个时间的修改大多是局部的,因此更新文件只需更新修改过的文件,其他 没有修改过的文件就没有必要上载到服务器.但一个稍微上规模的网 ...

  9. C#中abstract和virtual区别

    在C#的学习中,容易混淆virtual方法和abstract方法的使用,现在来讨论一下二者的区别.二者都牵涉到在派生类中与override的配合使用. 一.Virtual方法(虚方法) virtual ...

  10. GC学习笔记

    GC学习笔记 这是我公司同事的GC学习笔记,写得蛮详细的,由浅入深,循序渐进,让人一看就懂,特转到这里. 一.GC特性以及各种GC的选择 1.垃圾回收器的特性 2.对垃圾回收器的选择 2.1 连续 V ...