The original article was first published in the wechat public number: Jzm-blog, welcome to pay attention to the exchange!

The previous article implemented a date and time picker with the following github address:

https://github.com/jzmanu/MDatePickerSample
Copy the code

Use gradle dependencies directly:

compile 'com. Manu: MDatePicker: 1.0.0'
Copy the code

You can also check out the detailed introduction of the previous article or click to read the original text at the end of the article to see how to open source it, and click star to support it. The following will introduce how to upload the Android library project to JCenter for yourself or others to use. The specific reference is as follows:

  1. Registered account
  2. Create a warehouse
  3. Library project Configuration
  4. Upload library project
  5. Added to the JCenter
  6. Problems encountered

Registered account

Register a Bintray account and select a personal type to register for. Most people here will register as a corporate account when they first register. It seems that the corporate account cannot be added to JCenter, and there will be a fee for the enterprise version after the trial period.

// Personal account
https://bintray.com/signup/oss
// Corporate account
https://bintray.com/
Copy the code

Create a warehouse

The bintraytrate-Release plugin will upload the project to a repository named Maven if the repository name is not specified by repo. There is also a small hole here. The repository named Maven needs to be created manually. To make it easy to create a Repository called Maven, log in to your account and select Add New Repository:

If not, the following error is reported:

* What went wrong:
Execution failed for task ':dashview:bintrayUpload'.
> Could not create package 'smalllee/maven/dashview': HTTP/1.1 404 Not Found [message:Repo 'maven' was not found]

Copy the code

Then create a package with the same name as artifactId in the repository:

That’s the preparation for uploading the library project to JCenter. Let’s take a look at how the project side is configured.

Library project Configuration

Create a library module is used to separate store open to the public library Project, first under the Project build. Introducing bintray gradle file – release plug-in depends on:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com. Android. Tools. Build: gradle: 3.0.1'
        / / bintray - release the plugin
        classpath 'com. Novoda: bintray - release: 0.8.0'}}Copy the code

You can set the encoding format to UTF-8 to prevent errors during compilation and upload. You can also set the ignoring of improper checking of doc documents as follows:

allprojects {
    repositories {
        google()
        jcenter()
    }
    tasks.withType(Javadoc){
        // The generated doc document is not checked
        options.addStringOption('Xdoclint:none'.'-quiet')
        // Set the encoding format
        options.addStringOption('encoding'.'UTF-8')}}Copy the code

Then add the bintray-release plugin to the build.gradle file in the library module:

apply plugin: 'com.novoda.bintray-release'
Copy the code

Note that the bintrayrelease plugin must be introduced after com.android.library plugin. Otherwise, the final upload will indicate that the upload was successful, but in fact the upload was not successful.

:mdatepicker:xxx
:mdatepicker:xxx
// An error message was reported
:mdatepicker:bintrayUpload: Could not find publication: release.

BUILD SUCCESSFUL in 45s
Copy the code

Then define the upload library project in Task named Publish with the following key information:

publish{
    // Bintray.com username
    userOrg = 'jzman'
    // General write package name
    groupId = 'com.manu'
    // Specify the warehouse name
// repo = "maven"
    // Project name
    artifactId = 'MDatePicker'
    / / version number
    publishVersion = '1.0.0'
    // Project description
    desc = 'a goog date picker'
    // Project url
    website = 'https://github.com/jzmanu/MDatePickerSample'
}
Copy the code

Then you can upload the library project.

Upload library project

Before uploading, you need to obtain the API Key. Select Edit Profile as shown below:

Then select API Key and enter the user password to obtain the API Key:

After obtaining the API KEY, use the following upload command to upload:

Gradlew clean build bintrayUpload -pbintrayUser = User name -pbintrayKey =API KEY -pdryRun =false
Copy the code

The logs are as follows:

/ /...
:mdatepicker:releaseAndroidJavadocsJar
:mdatepicker:releaseAndroidSourcesJar
:mdatepicker:publishReleasePublicationToMavenLocal
:mdatepicker:bintrayUpload

BUILD SUCCESSFUL in 45s

Copy the code

Added to the JCenter

After successfully uploading, you can open the project details and select Add to JCenter to apply for adding to JCenter, as shown in the picture below:

You can then use the library project directly with dependencies as follows:

compile 'com. Manu: MDatePicker: 1.0.0'
Copy the code

Problems encountered

Most of the problems encountered have been described above, there is also a point to note if the following error occurs:


A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
com.novoda.gradle.release.AndroidLibrary$LibraryUsage.getDependencyConstraints()Ljava/util/Set;
Copy the code

I recommend that you check your gradle version. I need to change the gradle plugin version from 4.6 to 4.4 and reduce the gradle plugin version accordingly.

// Gradle plugin version
classpath 'com. Android. Tools. Build: gradle: 3.0.1'
/ / gradle version
distributionUrl=https\:/ / services.gradle.org/distributions/gradle-4.4-all.zip
Copy the code

In this way, you can open source your own library, and progress is simply a matter of practice and learning.