AndroidStudio发布依赖库至Jcenter

在这里只讲配置,注册什么的自行百度为。了发布成功大家一定要严格按照我这里配置,且注意看我写的注释

PS:Bintray主页 ,这个网站比较慢最好用VPN,不然能不能进去就看脸了。。如果有不明白可加Q:565265845

这是整个工程
在这里插入图片描述

  1. 首先配置gradle 4.4 到环境变量中去
  2. 在Bintray个人主页创建一个maven仓库,名字就叫maven
  3. 工程Gradle配置
buildscript {
    
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
  1. 用户信息
    在这里插入图片描述
  2. 要上传的Module的Gradle配置,注意要创建一个…/…/bintray.key里面写入用户信息 key=value 形式
apply plugin: 'com.android.library'

android {
    compileSdkVersion 28



    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}


/*********************上传jCenter依赖*********************/
apply plugin: 'com.novoda.bintray-release'

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.novoda:bintray-release:0.8.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

/**避免中文注释:编码GBK的不可映射字符**/
tasks.withType(Javadoc) {
    options {
        encoding "UTF-8"
        charSet 'UTF-8'
        links "http://docs.oracle.com/javase/7/docs/api"
    }
}

/**避免Javadocs错误:找不到引用**/
tasks.withType(Javadoc) {
    options.addStringOption('Xdoclint:none', '-quiet')
    options.addStringOption('encoding', 'UTF-8')
}
/**发布到我的Bintray仓库**/
def user = getPropertyValue('bintrayUser')    // 对应上图中的nelson-kk
def key = getPropertyValue('bintrayKey')    // 对应上图中的api-key
def org = getPropertyValue('userOrg')    // 对应上图中的nelson-kk

/**读取bintray.key文件的key**/
def getPropertyValue(String key) {
    if (key == null || key.length() == 0)
        return null

    File file = project.rootProject.file('../../bintray.key')
    if (!file.exists())
        return null

    InputStream inputStream = file.newDataInputStream()
    Properties properties = new Properties()
    properties.load(inputStream)

    //读取Key
    return properties.getProperty(key)
}

// 这里还有个选项是配置 maven 仓库如果没写 默认就是名叫 maven 的仓库

publish {
    bintrayUser = user
    bintrayKey = key
    dryRun = false
    userOrg = org
    groupId = 'com.nelson'
    artifactId = 'retrofit'
    publishVersion = '1.0.0'
    desc = 'Retrofit封装'
    website = 'https://github.com/Nelson-KK/RetrofitClient'  // 需要在GitHub上创建对应的仓库
    licences = ['Apache-2.0']
}
  1. 在Github创建对应的一个仓库名称叫做(RetrofitClient),这里创建仓库是为了对应到上面那个webSite的配置
  2. 发布 ------》 cd 到 retrofit 目录,点击AndroidStudio的Terminal默认是根目录下。 执行命令 -----》
gradle clean build bintrayUpload

等待上传成功

  1. Add to jcenter --》 点击 Add to jcenter 就可以啦
    在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/newMan1024/article/details/85336687