请先阅读:http://blog.saymagic.cn/2015/02/16/release-library-to-jcenter.html
最外面的build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() maven {url 'http://dl.bintray.com/tianzhijiexian/maven'} } dependencies { classpath 'com.android.tools.build:gradle:1.2.3' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' classpath 'com.github.dcendents:android-maven-plugin:1.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } }
app的build.gradle
apply plugin: 'com.android.library' apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray' // 这个version是区分library版本的,因此当我们需要更新library时记得修改这个version version = "1.0.0" android { compileSdkVersion 22 buildToolsVersion "22.0.1" resourcePrefix "随便填" defaultConfig { minSdkVersion 8 targetSdkVersion 22 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } lintOptions { abortOnError true } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) } def siteUrl = 'https://github.com/xxx/xxx' // 项目的主页 def gitUrl = 'https://github.com/xxx/xxx.git' // Git仓库的url group = "com.kale.xx" // Maven Group ID for the artifact,一般填你唯一的包名 install { repositories.mavenInstaller { // This generates POM.xml with proper parameters pom { project { packaging 'aar' // Add your description here name 'Extra xxx' //项目描述 url siteUrl // Set your license licenses { license { name 'The Apache Software License, Version 2.0' url 'http://www.apache.org/licenses/LICENSE-2.0.txt' } } developers { developer { id 'kale' //填写开发者基本信息 name 'kale' email 'xxxxx@qq.com' } } scm { connection gitUrl developerConnection gitUrl url siteUrl } } } } } tasks.withType(JavaCompile) { options.encoding = "UTF-8" } 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 } javadoc { options { encoding "UTF-8" charSet 'UTF-8' author true // 支持author标记 version true // 支持version标记 links "http://docs.oracle.com/javase/7/docs/api" } } artifacts { archives javadocJar archives sourcesJar } Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) bintray { user = properties.getProperty("bintray.user") key = properties.getProperty("bintray.apikey") configurations = ['archives'] pkg { repo = "maven" //发布到Bintray的那个仓库里,默认账户有四个库,我们这里上传到maven库 name = "ExtraXXXXX" //发布到Bintray上的项目名字 websiteUrl = siteUrl vcsUrl = gitUrl licenses = ["Apache-2.0"] publish = true } }
local.properties
## This file is automatically generated by Android Studio. # Do not modify this file -- YOUR CHANGES WILL BE ERASED! # # This file should *NOT* be checked into Version Control Systems, # as it contains information specific to your local configuration. # # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. sdk.dir=H:\Android\sdk bintray.user = 名字 bintray.apikey = 密钥
这时你会遇到一些坑,那么就赶快看看下面的文章是如何解决javadoc中的坑吧:
http://www.jianshu.com/p/c721f9297b2f?utm_campaign=hugo&utm_medium=reader_share&utm_content=note
这里还有一个示例:https://github.com/douo/lru-image/blob/master/library/build.gradle
参考自:
http://www.cnblogs.com/qianxudetianxia/p/4322331.html
http://www.linuxidc.com/Linux/2015-02/113874.htm
http://www.jcodecraeer.com/a/anzhuokaifa/Android_Studio/2015/0227/2502.html
http://blog.saymagic.cn/2015/02/16/release-library-to-jcenter.html