JCenter是Android Studio中repositories的默认节点。
申请Bintray账号
需要在Bintray注册一个账号
生成项目的JavaDoc和source JARs
JCenter需要我上传远程仓库以上两个文件,这一步需要android-maven-plugin插件,所以在项目中的build.gragle(项目最外层)构建依赖
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| buildscript{ repositories { jcenter(); } dependencies { classpath 'com.android.tools.build:gradle:1.0.0' classpath 'com.github.dcendents:android-maven-plugin:1.2' } allprojects { repositories { jcenter() } } }
|
然后在需要发布的那个module的build.gradle里配置修改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| apply plugin: 'com.android.library' apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray'
version = "1.0.0" android{ compileSdkVersion 21 buildToolsVersion "21.1.2" resourcePrefix "resourcePrefix" // 这个随便填 defaultConfig { minSdkVersion 9 targetSdkVersion 21 versionCode 1 versionName version } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs',include: ['*.jar']) compile 'com.nineoldandroid:library:2.4.0+' } def siteUrl = 'https://github.com/XXX/XXX' // 项目的主页 def gitUrl = 'https://github.com/XXX/XXX.git' // git仓库URL install { repositories.mavenInstaller { pom { project { packaging 'arr' name 'Project' // 项目名 url siteUrl licenses { // 协议 license { name 'The Apache Software License, Version 2.0' url 'http://www.apache.org/licenses/LICENSE-2.0.txt' } } developers { developer { // 基本信息 id 'seniorzhai' name 'zhaitao' email 'developer.zhaitao@gmail.com' } } 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.desinationDir } artifacts { archiver javadocJar archiver 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 = "ProjectName" websiteUrl = siteUrl vcsUrl = gitUrl licenses = ["Apache-2.0"] publish = true } }
|
上述的local.properties文件在项目的根目录,用于配置bintray账号信息,这个文件需要gitignore防止泄露账号信息
1 2
| bitray.user=your_user_name bitray.apokey=yor_apikey
|
Rebuild一下项目,module里的build文件夹会生成相应文件,项目生成到本地仓库,Android Studio默认在Android\sdk\extras\android\m2repository文件夹中
执行gradlew install
上传到Bintray
上传需要gradle-bintray-plugin的支持
在build.gradle里构建
1 2 3 4 5
| dependencies { ... classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' ... }
|
再Rebuild下,然后执行gradlew bintrayUpload
上传完成后就可再Bintray上找到Repo,最后申请Repo添加到JCenter,在https://bintray.com/bintray/jcenter输入项目的名字点击匹配到的项目,然后写一写Comments再send即可,等管理员审批即可。
成功后,在其他项目中调用添加denpendcies即可