Those of you who use Giithub regularly will be familiar with the following two images

Usually when we write an open source library, we publish it tomavenRepository, so that we can rely on our open source libraries remotely, without having toWhen using Eclipse+Ant, importing a library is done by downloading a JAR or AAR into the lib directory, then right-clicking and adding references.

When using Android Studio+Gradle, we can pull jars and AAR packages from the remote side and bring them locally as shown in the figure above.

Common Maven repositories

JCenter, MavenCenter, JitPack

When you create a new Android application, you’ll probably see the configuration shown above in the root directory of Gradle. In the latest Version of Android Studio 3.0, Google put its own dependency packages in Google (). At first, Android Studio used mavenCenter as the default repository address, but due to the slow upload speed of mavenCenter, The operation was not friendly, and Android Studio later replaced the default repository address with JCenter. If you are a developer of AS 2, the default repositories in AS are mavenCenter and JCenter, and if you are a developer of AS 3, the default repositories in AS are mavenCenter, JCenter and Google.

So what is the Jitpack?

Jcenter and mavenCenter are the default standard Android repositories, so they define an alias. MavenCenter and JCenter are the default Standard Android repositories. So some custom repositories are written this way and then fill in their own repository url, for example

Bintray

The JCenter library is hosted on Bintray, so we first need to register an account in Bintary, then create our own Maven repository, and then release our open source library to the Maven repository on Bintary. Finally, submit our open source library to JCenter. The process is like this, well of course not so simple, the following is to introduce the specific operation process.

1. Create a Bintray account

This is the home page of Bintary, but we cannot directly click the green button in the picture to register, because Bntary adds the concept of Organization. By clicking the green button, we will be able to create an account for the Organization by default.

So where are personal accounts created?

https://bintray.com/signup/oss

So this is the address up here, and I click on it to create a personal account, and I click on it like this

Click Create A Maven repository once you have logged in successfully

Enter the warehouse configuration information and select Maven for type

You will see the following page. The maven repository I created here is called MyLibrary

2. Obtain the API key

Click on Edit Profile in the upper right corner of the page and save our API key by following the steps shown in the picture. Through API Key we can publish our open source library in Android Studio to Bintray.

3. Configure our open source libraries

As you can see, we created a new Android-Bintray-Build Android project, and we created a Library moudle called BintrayBuild, and this is the open source Library that we’re going to upload. After creating the project, upload it to Github.

There are two ways to upload. The first is through bintray’s official plugin

bintray/gradle-bintray-plugin

The second is an open source plugin for a foreign organization

novoda/bintray-release

Here’s how to use these two plug-ins in turn

bintray/gradle-bintray-plugin

1. Add plugin dependencies in build.gradle in the project root directory

2. Configure our open source library information in gradle.properties under the root directory of the project

3. Fill in our user and API key in local.properties under the root directory of the project. This content can be stored in gradle.properties. If this is the case, our API key will be exposed to others, which of course is not possible, so we will configure our API key in local.properties, which Git ignores.

4. Under our open source library directory, create a bintray.gradle file for uploading open source library and configuration release files, including source code, documents and AAR.

Here’s the difference between an AAR and a JAR.

*.jar: contains only class files and manifest files, not resource files, such as images, all files in res.

*. Aar: contains all resources, including all class and RES resource files.

If you are just a simple library, use the generated *.ja r file; Use *.aar files only if you have a UI library that contains your own control layout files, fonts and other resource files.

Gradle = bintary. Gradle = bintary. Gradle = bintary.

6. When all the above configuration is complete, we can upload our open source library, open Terminal, execute./gradlew install, and when complete, Open the Build directory and you’ll find the AAR package, javadoc documentation, sources source code, and poM configuration files for Maven.

/gradlew bintrayUpload: /gradlew bintrayUpload: /gradlew bintrayUpload

Once the release is complete, open the Bintray page and you’ll see that the maven repository we just released is already in the repository we created earlier.

novoda/bintray-release

Uploading with this plugin is relatively easy and only takes two steps

1. Add plugin dependencies in build.gradle in the project root directory

2. Configure upload information in the build.gradle directory of the open source library, also at the end of the file.

3. Release our open source project. Enter the following command in Terminal to replace BINTRAY_USERNAME and BINTRAY_KEY with your own user and API key.

So our open source library has been uploaded successfully.

Published to JCenter

On the Bintray open Source library page, there is a “Add to JCenter” message on the right. Click “Commit” and you will be told you have added in a few hours or a day.

Use our open source libraries

Here I would like to introduce our previous configuration information. The configuration information of the two publishing methods is consistent

bintray/gradle-bintray-plugin As an example.

PROJ_NAME: Name of the open source library

PROJ_GROUP: id of the group used for uploading

PROJ_ARTIFACID: Indicates the artifactId or Projectid used

PROJ_VERSION: release version

PROJ_WEBSITEURL: Github address

PROJ_ISSUETRACKURL: Indicates the Issue address

PROJ_VCSURL: Git address

PROJ_DESCRIPTION: Description of the open source library

So when our library is published, Gradle’s dependency address is in the following format:

If you successfully publish to JCenter, you can directly rely on your own project according to the above rules.

If you are not publishing to JCenter, add your Maven repository address to build.gradle in the project root directory.

Matters needing attention

1. Different open source libraries need to be uploaded to different Github repositories, because we will specify the Github address of the open source library on bintray, please ensure that it is unique.

With the release of Android Studio 3.0, Gradle has been updated to 4.1+. In versions after Gradle 3.6, we have added new dependency commands like implementation and API. Gradle versions of both plug-ins are below 3.6, so they do not support the new commands. This will cause an error when your Labrary relies on other open source projects. If you use new dependency commands like implementation and API, when generating aar and Maven POM files, The POM file does not configure the other libraries that you depend on in Labrary. This way, when building dependencies with Labrary, Gradle does not download the libraries that you depend on in Labrary. ClassNotFound errors are raised when using these libraries. So keep using the old compile dependency command while the above two plug-ins have not been updated to the latest version of Gradle.

3. For more information about new dependencies for Android Studio 3.0, check out the previous update: New dependencies for Android Studio 3.0

The source code

The code for the above two upload methods has been posted to Github. For more configuration, please refer to the code on Github. The address is as follows:

https://github.com/Werb/android-bintray-build

If you have a good open source library can be directly in the public number to send your warehouse address, share it together!

Explore new and interesting things

Android, Kotlin, Design, product, Thinking, games.

Long press attention

If you find it interesting, share it