Android Studio submit library to Bintray jCenter from entry to abandon

In our work, we often refer to third-party open source libraries, such as butterknife, Gilde, RxJava, etc. The easiest and fastest way is to use compile reference in gradle, for example

compile 'io.reactivex:rxjava:1.1.3'

Have you ever thought about writing an open source library yourself to provide a reference for others to use? This article describes how to create a library for others to use.

First of all you need to have a library

Creating a library is very simple, there are a lot of examples and tutorials on the Internet, in order to save space, this article only briefly introduces.
Create a common project in AndroidStudio first, then right-click on the created project and select ->New->Module

 

Paste_Image.png


Select'Android Library' in the pop-up window, so that the legendary aar package is created, a package similar to the traditional jar.
Then choose a domineering name, and that's it! (But if you want your main project to use this lib, you need to configure it in build.gradle. Many online articles don't introduce it)

 

Next is Bintray and jCenter

What is Bintray? What is jCenter?
First of all, jCenter is a code library, which is equivalent to a public storage control. Simply put, you package and upload things like aar files and some document description files that you have written to the jCenter server. Others can The package you uploaded is downloaded through the jCenter server.
What about Bintray? Bintray is the provider of jCenter. It supports uploading lib to multiple platforms. jCenter is just one of many platforms. It is vividly said that jCenter is a warehouse located in a certain place, and Bintray is a delivery truck, and the library you write is the goods.

Therefore, if we want to share the lib we wrote with others, we must upload it to jCenter through Bintray. First of all, we have to register an account on Bintray , or log in directly with a Github account.
After logging in, copy the API Key at the bottom of the left menu on the https://bintray.com/profile/edit page.

Paste_Image.png

Join in the Root gradle of the project

dependencies {
    ....
    classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
    classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
}

Can refer to

Add in the gradle of the library:

apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
version = "0.1.1" // 修改为你的版本号

def siteUrl = 'https://github.com/h3clikejava/ExtendImageView' // 修改为你的项目的主页
def gitUrl = 'https://github.com/h3clikejava/ExtendImageView.git' // 修改为你的Git仓库的url

group = "h3c.extendimageview" // Maven Group ID for the artifact,一般填你唯一的包名

install {

    repositories.mavenInstaller {

        // This generates POM.xml with proper parameters
        pom {

            project {

                packaging 'aar'

                // Add your description here
                name 'auto extand ImageView for Android.' //项目描述

                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 'H3c' //填写的一些基本信息
                        name 'H3c'
                        email '[email protected]'
                    }
                }

                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 = "extend-imageview" //发布到JCenter上的项目名字
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = ["Apache-2.0"]
        publish = true
    }
}

The code is a bit messy, it's lazy, but it's actually quite simple. Just copy the above paragraph and modify it to your own parameters. For details, please refer to here

Here you also need to write your bintray username and apikey into the local.properties file of the project

// 示例值, 仅供参考
bintray.user=h3 // your bintray user name
bintray.apikey=c5434272d522d35d1a0123459981225564155753 // your bintray api key

OK, the above configuration is ready to upload to Bintray.
Execute through gradew

gradew install
gradew bintrayUpload

Paste_Image.png

Usually everyone fails for many reasons. It is very cheating not to introduce here! Because the follow-up of this article will teach you to give up this lengthy and easy failure method.

If you compile successfully and upload to Bintray normally, then congratulations, you are really amazing, and then it will be easy for you

See your version in Versions to indicate success, then click Add to JCenter

 

Paste_Image.png

 

Enter some description and wait for review. After the review is completed, it can be referenced in the third-party library.

Easier way novoda

After reading the above content, I believe you already know how to write a lib library and upload it to jCenter through bintray. But do you think it's really complicated...There are so many things to configure in build.gradle, it's almost impossible to write it out with your eyes closed, you can only search and paste it online.

Next, a simpler way is to use the novoda library, which still uses bintray and jCenter, but it will greatly simplify the configuration of build.gradle.
First add this sentence in Root gradle

apply plugin: 'com.novoda.bintray-release' // must be applied after your artifact generating plugin (eg. java / com.android.library)

Note that it must be written under com.android.library and
then write this in your lib gradle

publish { 
    userOrg = 'novoda' 
    groupId = 'com.novoda' 
    artifactId = 'bintray-release' 
    publishVersion = '0.3.4' 
}

Need to be added in android{}

lintOptions {
    abortOnError false
}

Paste_Image.png

Run in the AS terminal at this time

$ ./gradlew clean build bintrayUpload -PbintrayUser=BINTRAY_USERNAME -PbintrayKey=BINTRAY_KEY -PdryRun=false

Replace BINTRAY_USERNAME with your binary name and BINTRAY_KEY with your Bintray key.

Congratulations if you succeed, if you fail...there are many reasons, this article is cheating and wo n't introduce it! Rejoice is so self-confident, students who like Bintray jCenter can toss on their own!

Wenwei welfare, yes I am Rejoice

jCenter should be the most widely used third-party gradle warehouse at present, but its application to create, compile, upload and other processes is too troublesome. It feels that it is a product of the 1980s and needs to be uploaded, compiled by yourself, and reviewed. , Is it super easy to fail? ? ?

This article decides to present the 82 years of Rejoice, which has been collected for many years, for everyone, and the bloggers respect it first!
JitPack is also a code repository, equivalent to jCenter, but there are not as many people who use jCenter temporarily, but more and more open source projects start to use JitPack.

It's really very, very simple, let's see how simple it is.
For example, the blogger wrote a basic Android library for his own use, which is convenient for quick construction of the project. The address is:
AFastProject (for children who don’t give me a reward, remember to point me to the stars...). Because of the third-party library, I use this article There are problems with the above two ways of publishing aar. There are various, either it cannot be compiled, or it is lost. Anyway, it has been a long time. Finally solved it with JitPack in one sentence. . . .

First open the URL http://jitpack.io

Paste_Image.png

 

Enter your Github project address in the input box, click Look up and
it will automatically traverse your recently submitted and published versions

Paste_Image.png

 

Click on the option you want to quote Get it

Paste_Image.png

I will tell you how to cite at the end of the article.
Yes, you read that right, the client does not need to change anything. Other projects can be directly quoted!

Haha...I'm so confident with Rejoice



Author: H3c
link: https: //www.jianshu.com/p/31410d71eaba
Source: Jane books
are copyrighted by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.

Guess you like

Origin blog.csdn.net/qq_37381177/article/details/111366310