使用 gradle-bintray-plugin 发布项目到jcenter

1.注册

1.在Bintary上注册账号,红色框框看见没

2.Add New Repository 创建maven

2.工程

1.创建Android工程 及 Library

创建一个工具类 调用showLog() 则打印    Log.w("hello world","i am from androidlibrary")

3.配置 gradle-bintray-plugin

1.Project的build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.2.71'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'

    }
}

allprojects {
    repositories {
        google()
        jcenter()
      
    }
    tasks.withType(Javadoc) {
        options.addStringOption('Xdoclint:none', '-quiet')
        options.addStringOption('encoding', 'UTF-8')
        options.addStringOption('charSet', 'UTF-8')
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

//完成2.3.后配置
tasks.getByPath(":androidlibrary:javadoc").enabled = false

2.LibraryModule目录下新建 install.gradle 及 publish.gradle

install.gradle

//instal.gradle
apply plugin: 'com.github.dcendents.android-maven'

group = publishedGroupId                               // Maven Group ID for the artifact

install {
    repositories.mavenInstaller {
        // This generates POM.xml with proper parameters
        pom {
            project {
                packaging 'aar'
                groupId publishedGroupId
                artifactId artifact

                // Add your description here
                name libraryName
                description libraryDescription
                url siteUrl

                // Set your license
                licenses {
                    license {
                        name licenseName
                        url licenseUrl
                    }
                }
                developers {
                    developer {
                        id developerId
                        name developerName
                        email developerEmail
                    }
                }
                scm {
                    connection gitUrl
                    developerConnection gitUrl
                    url siteUrl

                }
            }
        }
    }
}

publish.gradle

//publish.gradle
apply plugin: 'com.jfrog.bintray'

version = libraryVersion


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
}

task findConventions << {
    println project.getConvention()
}

artifacts {

    archives javadocJar
    archives sourcesJar
}

// Bintray
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 = bintrayRepo
        name = bintrayName
        desc = libraryDescription
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = allLicenses
        publish = true
        publicDownloadNumbers = true
        version {
            desc = libraryDescription
            gpg {
                sign = true //Determines whether to GPG sign the files. The default is false
                passphrase = properties.getProperty("bintray.gpg.password")
                //Optional. The passphrase for GPG signing'
            }
        }
    }
}

3.LibrarModule的build.gradle

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'com.github.dcendents.android-maven'//需添加的
apply plugin: 'com.jfrog.bintray'//需添加的
version = "1.0.0"//版本号,每次更新记得修改
android {
    compileSdkVersion 28

    defaultConfig {
        minSdkVersion 21
        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'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

//gradlew bintrayUpload
//下面到结尾都是需要添加的
ext {
    bintrayRepo = 'MyTestMaven' // 对应Bintray网站中,创建Repository的命名
    bintrayName = 'androidlib' // 对应Bintray网站中,创建的package的命名(會新建)

    publishedGroupId = 'com.cuzyou.android' // 随意,对应之后引用工程的 第一段名称
    libraryName = 'MyTestLibrary'    // 最好是工程名
    artifact = 'MyTestLibrary'    // 最好是工程名,对应之后引用工程的 第二段名称

    libraryDescription = 'Library of tools used in development' // 工程的描述

    siteUrl = 'https://github.com/cuzyou' // github项目地址
    gitUrl = 'https://github.com/cuzyou' // github项目地址git

    libraryVersion = this.version // 随意,对应之后工程的 第三段名称

    developerId = 'cuzyou' // 用户名ID,对应创建bintray账号的名称ID
    developerName = 'cuzyou' // 用户名ID,对应创建bintray账号的名称ID
    developerEmail = '****.com' // 邮箱,对应创建bintray账号的邮箱

    licenseName = 'The Apache Software License, Version 2.0' // 固定
    licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' // 固定
    allLicenses = ["Apache-2.0"] // 固定
}

apply from: 'install.gradle'
apply from: 'publish.gradle'

javadoc { // 引用这个,是为了解决注释中,有中文,然后编译不通过的坑
    options {
        encoding "UTF-8"
        charSet 'UTF-8'
        //author true
        version true
        title 'A LibSDK Support For Android'   // 文档标题
    }
}

4.在local.properties 配置Bintary的 user 和 apikey

## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Thu Nov 22 10:54:41 CST 2018
bintray.user=Bintray上的user
bintray.apikey=Bintray上的apikey

4.上传项目 gradlew bintrayUpload

1.如果有如下报错

已知解决方案:

(1)挂上你的VPN

(2)

(3)

再次 gradlew bintrayUpload ,build successful 则成功上传

5.审核使用

1. Add to JCenter 进行审核,内容不要为空

    审核成功就可以直接 implementation 'com.cuzyou.android:MyTestLibrary:1.0.0'

2. 使用审核中的开源项目

(1) 在Project的 build.gradle中添加

allprojects {
    repositories {
        google()
        jcenter()
        maven {url 'https://dl.bintray.com/cuzyou/MyTestMaven'}
    }
}

(2) 在app的build.gradle添加依赖

implementation 'com.cuzyou.android:MyTestLibrary:1.0.0'

3.测试:调用MyTestLibrary中工具类的方法

6.更新Library

修改LibraryModel的build.gradle中  version = "1.0.0",每次版本号必须大于上次版本号

7.友情提示

项目提交GitHub的时候记得别提交local.properties哈,附上.gitignore

# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
.idea/caches

# Keystore files
# Uncomment the following line if you do not want to check your keystore files in.
#*.jks

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Google Services (e.g. APIs or Firebase)
google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json

# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md

*.iml
.gradle
/local.properties
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
.DS_Store
/build
/captures
.externalNativeBuild

8.项目地址有毛病不关我事哈

9. 吗的这么长,告辞

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值