上篇文章是通过简单的配置方法进行上传到jcenter,看起来不具有普遍性,故作下文
第一步:
在项目的根 build.gradle中加入如下引入classpath
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'
第二步:
在包的build.gradle中加入如下配置信息
apply plugin: 'com.android.library' // 根节点添加 apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray' // 根节点添加 version = "0.1" android { compileSdkVersion 17 buildToolsVersion "22.0.1" defaultConfig { minSdkVersion 8 targetSdkVersion 17 } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } } def siteUrl = 'https://github.com/openproject/LessCode' // #CONFIG# // project homepage def gitUrl = 'https://github.com/openproject/LessCode.git' // #CONFIG# // project git group = "com.jayfeng" install { repositories.mavenInstaller { // This generates POM.xml with proper parameters pom { project { packaging 'aar' name 'Less Code For Android' // #CONFIG# // project title 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 'ajiang' // #CONFIG# // your user id (you can write your nickname) name 'ajiang' // #CONFIG# // your user name email '********@qq.com' // #CONFIG# // your email } } scm { connection gitUrl developerConnection gitUrl url siteUrl } } } } } 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 } 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" name = "alipay" // #CONFIG# project name in jcenter websiteUrl = siteUrl vcsUrl = gitUrl licenses = ["Apache-2.0"] publish = true } }
第三步:
在local.properties中加入如下
sdk.dir=D\:\\Android\\sdk bintray.user=githubnewer bintray.apikey=your key
最后:
进行命令行控制
gradlew javadocJar
gradlew sourcesJar
gradlewinstall
gradlew bintrayUpload
注1:如上方式很简单,但是在操作中会遇到不少问题,比如如下问题困扰我半天,最后终于解决了,特此记录一下
此原因是因为项目使用的gradle版本是2.4+,而插件版本是1.3-导致的
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
classpath 'com.github.dcendents:android-maven-plugin:1.2'
解决:在gradle.wrapper中
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
注2:在输入命令行的时候会遇到如下问题
* What went wrong:
Execution failed for task ':MaterialDesign:javadoc'.
> Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting): 'D:\360\test\MaterialDesignLibrary-master\MaterialDesignLibrary\MaterialDesign\build\tmp\javadoc\javadoc.options'
向上翻查阅相关日志后发现,
D:\360\test\MaterialDesignLibrary-master\MaterialDesignLibrary\MaterialDesign\src\main\java\com\gc\materialdesign\widgets\SnackBar.java:153: 错误: 编码GBK的不可映射字符
// TODO 鑷姩鐢熸垚鐨勬柟娉曞瓨鏍?
应该是编码问题,导致build failed,所以只要将其转码即可
在包的build.gradle中加入
javadoc { options{ encoding "UTF-8" charSet 'UTF-8' } }