新建函式庫及添加properties文件
1. 於專案中建立module
選擇Android Library
輸入自訂的module name
2. 於專案層級( Project: Application) build.gradle 添加依賴
新增:classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.2'
3. 於Module下新增bintrayUpload.gradle、local.properties、project.properties
bintrayUpload.gradle (該檔不用做修改)
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
// load properties
Properties properties = new Properties()
File localPropertiesFile = project.file("local.properties");
if(localPropertiesFile.exists()){
properties.load(localPropertiesFile.newDataInputStream())
}
File projectPropertiesFile = project.file("project.properties");
if(projectPropertiesFile.exists()){
properties.load(projectPropertiesFile.newDataInputStream())
}
// read properties
def projectRepositoryName = properties.getProperty("project.repositoryName")
def projectName = properties.getProperty("project.name")
def projectGroupId = properties.getProperty("project.groupId")
def projectArtifactId = properties.getProperty("project.artifactId")
def projectVersionName = android.defaultConfig.versionName
def projectPackaging = properties.getProperty("project.packaging")
def projectSiteUrl = properties.getProperty("project.siteUrl")
def projectGitUrl = properties.getProperty("project.gitUrl")
def developerId = properties.getProperty("developer.id")
def developerName = properties.getProperty("developer.name")
def developerEmail = properties.getProperty("developer.email")
def bintrayUser = properties.getProperty("bintray.user")
def bintrayApikey = properties.getProperty("bintray.apikey")
def bintrayOrganizationId = properties.getProperty("bintray.organizationId");
def javadocName = properties.getProperty("javadoc.name")
group = projectGroupId
// This generates POM.xml with proper parameters
install {
repositories.mavenInstaller {
pom {
project {
name projectName
groupId projectGroupId
artifactId projectArtifactId
version projectVersionName
packaging projectPackaging
url projectSiteUrl
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id developerId
name developerName
email developerEmail
}
}
scm {
connection projectGitUrl
developerConnection projectGitUrl
url projectSiteUrl
}
}
}
}
}
// This generates sources.jar
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))
}
// This generates javadoc.jar
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
}
// javadoc configuration
javadoc {
options{
encoding "UTF-8"
charSet 'UTF-8'
author true
version projectVersionName
links "http://docs.oracle.com/javase/7/docs/api"
title javadocName
}
}
// bintray configuration
bintray {
user = bintrayUser
key = bintrayApikey
configurations = ['archives']
pkg {
userOrg = bintrayOrganizationId
repo = projectRepositoryName
name = projectName
websiteUrl = projectSiteUrl
vcsUrl = projectGitUrl
licenses = ["Apache-2.0"]
publish = true
}
}
local.properties
#bintray
bintray.user=你在bintray的使用者名稱(非帳號)
bintray.apikey=你的使用者api key
#developer
developer.id=同user
developer.name=自訂開發者名字
developer.email=自訂開發者信箱
project.properties
#project
project.repositoryName=repository的名稱
project.name=建立在repository內package的名稱
project.groupId=APP的專案包全名(例如 com.example)
project.artifactId=APP的module的包名稱 (例如 mylibrary)
project.packaging=aar(不需做修改)
project.siteUrl=個人網址若無免填
project.gitUrl=個人github網站若無免填
#javadoc
javadoc.name=同project.name
最後,於新建Module的build.gradle最底下加入gradle引入
apply from: "bintrayUpload.gradle"