Android studio 使用Gradle发布Android开源项目到JCenter 总结

一、注册帐号java

    先到https://bintray.com注册一个帐号。  这个网站支持 github 帐户直接登陆的android

 

二、获取  bintray.user  和 bintray.apikey git

       2.1:bintray.user 就是你的用户名,注意是用户名,不是邮箱github

           在注册的时候会出现这个界面web

              

              或者apache

 

                                                   

 

       2.2 获取 bintray.apikey api

            

 

三、在Android studio 项目中建立一个 library Module  , 这个 Module 的名字 是 ZYJ ,以下oracle

  

 

四、在项目的根目录的 local.properties ( 这个文件是我的隐私 , 利用gitignore忽略这个文件到git ) 文件填写  bintray.user  和 bintray.apikey app

      

 

五、在项目的根目录的 build:gradle 文件里面添加插件 代码 less

 

 classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'

  截图以下 

       

 

六、配置 库文件项目中的 build:gradle 文件,也就是 ZYJ Module  的build:gradle 文件

apply plugin: 'com.android.library'

//配置插件
apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray' version = "1.0.0"       //这个是版本号,必须填写
 android { compileSdkVersion 23 buildToolsVersion "23.0.1" resourcePrefix "less_"     //这里随便填
 defaultConfig { minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.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.0' } def siteUrl = 'https://github.com/zyj1609wz'      // 项目的主页 这个是说明,可随便填
def gitUrl = 'https://github.com/zyj1609wz'      // Git仓库的url 这个是说明,可随便填
group = "zyj.com.mylibrary"    // 这里是groupId ,必须填写 通常填你惟一的包名
 install { repositories.mavenInstaller { // This generates POM.xml with proper parameters
 pom { project { packaging 'aar'
                // Add your description here
                name 'Android BounceProgressBar Widget'     //项目描述
 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 'zhaoyanjun'        //填写开发者的一些基本信息
                        name 'zhaoyanjun'    //填写开发者的一些基本信息
                        email '1643915516@qq.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.destinationDir } artifacts { archives javadocJar archives sourcesJar } Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) bintray { user = properties.getProperty("bintray.user")    //读取 local.properties 文件里面的 bintray.user
    key = properties.getProperty("bintray.apikey")   //读取 local.properties 文件里面的 bintray.apikey
    configurations = ['archives'] pkg { repo = "maven" name = "ZYJ"    //发布到JCenter上的项目名字,必须填写
        websiteUrl = siteUrl vcsUrl = gitUrl licenses = ["Apache-2.0"] publish = true } }

 

七、同步代码 

     

 

八、若是第7步没有问题了,就能够把项目上传到Bintray

     8.1  下载一遍Gradle 

            执行命令  gradlew install

            怎么才能执行上面的命令呢??

         8.1.一、打开Android studio 左下角的  Terminal 

              

       

         8.1.2 在输入框中输入  gradlew install ,而后回车执行 

                 

 

         

        8.1.3 在8.1.2 可能出现的错误 

               错误截图  

 

                      

           

             解决方案 : 在ZYJ Module 的 build:gradle  中添加如下代码              

javadoc { options{ encoding "UTF-8" charSet 'UTF-8' author true version true links "http://docs.oracle.com/javase/7/docs/api" } }

   

         8.2   而后执行以下命令(Windows中)完成上传 

                  执行命令  gradlew bintrayUpload 

 

                 

 

九、进入Bintray 网站,若是看到下面这些就表明你上次成功了

       

                 

                  

十、若是看到以下的信息就表明能够把 项目添加到 JCenter  

     

           

 

 

 

     11 、把项目提交到 Jcenter 中              

             

 

                    

 

      提交成功后,等待几个小时,就能够审核经过了。

 

十二、审核经过了,如何使用 ?

        在 app Module   的 build:gradle  里面添加 

         compile 'zyj.com.mylibrary:ZYJ:1.0.0'

        注意: 

                  zyj.com.mylibrary:是groupId 

                   ZYJ: 项目名

                   1.0.0:版本号           

         

       

1三、如何 删除  bintray.com 里面已经发布的 项目

        

 

                     

 

1四、如何发布更新版本

       只须要在发布的时候把 版本号更新,就能够了,发布完成,不须要 add jcenter 操做。等待几个小时,就能够使用新版本了。

        

相关文章
相关标签/搜索