将Android Studio开源项目提交到JCenter

本文详细介绍如何将Android项目发布到JCenter的过程,包括在Bintray注册账号、配置local.properties文件、设置build.gradle文件等内容,并分享了提交过程中遇到的问题及解决办法。
  • bintray注册账号;
  • edit记住你的name和API KEY,可以把这些信息放在local.properties文件中;
//local.properties
sdk.dir=/Applications/ADT/sdk
bintray.user = ***
bintray.apikey = *************************
  • 配置工程的build.gradle
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        jcenter()
    }
}

注意com.github.dcendents:android-maven-gradle-plugin名称和版本,引入android-maven-plugin和gradle-bintrayl-plugin 插件;

  • 配置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 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.2'
}

def siteUrl = 'https://github.com/fyales/tagcloud'      // 项目的主页
def gitUrl = 'https://github.com/fyales/tagcloud.git'   // Git仓库的url
group = "com.fyales.android"
install {
    repositories.mavenInstaller {
        pom {
            project {
                packaging 'aar'
                name 'Android TagCloud'    //项目描述
                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 'fyales'        //填写的一些基本信息
                        name 'fyales'
                        email 'fyales@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.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 = "TagCloud"    //发布到JCenter上的项目名字

        websiteUrl = siteUrl

        vcsUrl = gitUrl

        licenses = ["Apache-2.0"]

        publish = true

    }

}

这串代码主要做了三件事

生成JavaDoc

生成Jar

配置我们项目的信息

在这里我要提醒一下,生成javadoc和jar是必选选项。一开始我认为做这些没有必要,所以没有写入生成javaDoc和jar的命令,于是,我收到了bintray的官方邮件(邮件中是另外一个项目):

Bintray (bintray) has sent you a direct message from Bintray:

Hi, 

Jcenter hosts java applications that follows maven convention.
In addition to the .aar and pom files in the path: /com/fyales/parser/1.0.0
, your version should include a sources jar, and optionally a javadoc jar. 

Your files should be under a maven path layout.
(see https://bintray.com/docs/usermanual/uploads/uploads_includingyourpackagesinjcenter.html)

Once those files are added, we'll be glad to include your package in JCenter.

Regards,
Bintray Support

在这边还有一个坑我写的javadoc命令一开始运行失败,这是因为我喜欢在我的注释这样写

@author fyales

@date

因为javadoc里面并没有@date,所以会解析失败,大家也要注意一下。。。。。。。

  • 运行下面的命令将你的项目提交到Bintray
./gradlew bintrayUpload
  • 提交审核

提交完成之后,你就可以申请你的项目到JCenter,点击Include My Package,在弹出的界面输入你的项目名称确定就可以了,当审核通过后,你就可以直接用你自己项目了.

  • 引用
dependencies {

    compile 'com.fyales.android:library:1.0.0'

}

转载于:https://my.oschina.net/yale8848/blog/639239

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值