Describes how to upload your project to JCenter.

preface

Compile scripts we often see compile scripts in Android Gradle files. These scripts are actually pulled from the library because the developer of the previous library put the jar or AAR file of the corresponding library on a remote server.

compile 'com. Android. Support: recyclerview - v7:27.0.0'
compile 'com. Squareup: otto: 1.3.7'
compile 'com. Squareup. Picasso was: Picasso was: 2.5.2'
compile 'com. Squareup. Okhttp: okhttp: 2.4.0'
compile 'com. Squareup. Retrofit: retrofit: 1.9.0'Copy the code

What is the AAR

This is because the AndroidLibrary typically requires built-in Android specific files, such as Manifest, Resources, Assets, or JNI, in formats beyond the JAR file standard.

The JAR package is part of the AAR file package that is embedded.

Configuration rules

The string arrangement rule behind compile is

GROUP_ID:ARTIFACT_ID:VERSION

GROUP_ID

It is usually named after the developer’s package name.

It is possible that there are several libraries in the same context that can share the same GROUP_ID

ARTIFACT_ID

Define the library’s real name, such as Picasso

VERSION

The version number is in X.X.X format

Android project Preparation

Take a simple demo where the project address is

Github.com/hgDendi/And…

Is a HelloWorld project where the string comes from a static method of the Mylib abstract class under myLib Module.

Mylib is also the class we need to upload to JCenter this time.

project

The Module partition

Generally, the library to be uploaded should be a separate module, i.e. 1 Module per 1 library.

Generally divided into library modules and the use of demo modules.

If you want to have more than one library, divide up multiple modules.

For example, the following project structure.

1510486146328

bintray

Sign up for an account and go to bintray.com.

The new warehouse

Click “Add New Repository” in the Personal Administration window.

1510486324520

Then create a Maven repository

1510486374030

Once you’ve created it, I’m gonna say “Create New Package”

WX20171112-193514@2x

Enter the corresponding information. Website and VersionControl can be set to the Github address, and issue to the Github issue address

WX20171112-193746@2x

Click On CreatePackage to create your Maven server on Bintray.

Project Document Preparation

Project#gradle

Add dependencies to the Project gradle file

buildscript {
    ...

    dependencies {
        classpath 'com. Android. Tools. Build: gradle: 3.0.0'
        classpath 'com. Jfrog. Bintray. Gradle: gradle bintray - plugin: 1.6'
        classpath 'com. Making. Dcendents: android - maven - gradle - plugin: 1.4.1'}}Copy the code

local.properties

Add user information to local.properties.

Since Gitignore automatically ignores local.properties, it’s safe to put private information there.

bintray.user=[...]  bintray.apikey=[...]  bintray.gpg.password=[...]Copy the code

The apiKey can be seen in the EditProfile

APIKEY

The module of the build. Gradle

Add information to the build.gradle file in the lib Module based on the information in the previous steps.

apply plugin: 'com.android.library'

ext {
      // The name of the repository you just created
    bintrayRepo = 'testMaven'
      // The package name
    bintrayName = 'mylib'

      / / the groupID of the owner
    publishedGroupId = 'com.hgDendi.test'
    libraryName = 'MyLib'
    artifact = 'mylib'

    libraryDescription = 'lib test demo'

    siteUrl = 'https://github.com/hgDendi/AndroidJCenterDemo'
    gitUrl = 'https://github.com/hgDendi/AndroidJCenterDemo.git'

    libraryVersion = '0.0.1'

    developerId = 'dendi'
    developerName = 'Dendi Chan'
    developerEmail = '[email protected]'

    licenseName = 'The MIT License'
    licenseUrl = 'https://rem.mit-license.org'
    allLicenses = ["MIT"]}Copy the code

As shown above, the resulting Gradle Script will be

compile 'com. Hgdendi. Test: mylib: 0.0.1'Copy the code

Adding script dependencies

Add a line apply from to the build.gradle file in the lib Module

apply from: 'https://raw.githubusercontent.com/hgDendi/AndroidJCenterDemo/master/bintray.gradle'
apply from: 'https://raw.githubusercontent.com/hgDendi/AndroidJCenterDemo/master/maveninstall.gradle'Copy the code

Upload code

Run the gradlew command to upload the lib

./gradlew install
./gradlew bintrayUploadCopy the code

Log on to Bintray and see the upload result.

uploadSuccess

Synchronization to jcenter

The code is still in your Maven repository and not synchronized to JCenter.

Click on your package and AddToJCenter to upload the code to JCenter.

add2Jcenter

Uploaded successfully

Synchronizing to JCenter can sometimes take anywhere from half a day to a day.

Once the synchronization is successful, you can use compile to pull the lib from the server.

dependencies {
// implementation project(':mylib')
    compile 'com. HgDendi: mylib: 1.0.0'
}Copy the code

library