Android released the Android Library project to JCenter in 5 minutes

Source: Internet
Author: User
Tags jfrog jcenter

Android released the Android Library project to JCenter in 5 minutes

Android-library-publish-to-jcenter is a project that helps Android Developers publish the AAR library to jcenter, android-library-publish-to-jcenter has encapsulated the script to be written, we only need to configure relevant properties to release our project to JCenter within 5 minutes (excluding the review time)

1. Register a Bintray account (portal)

Bintray is the publisher of The jcenter. Therefore, you must register a Bintray account and write down your user name and API Key after registering the account.

After logging on to the homepage, click the user name in the upper-right corner to enter the personal homepage. Then click Edit under the user name to enter the personal information editing page. Next, click the last API Key in the list on the left of the page.

Click the copy button indicated by the rightmost arrow to copy your API Key.

2. Check the Android plug-in version

First, check the version of your Android plug-in. Because 1.1.0 has a BUG that will cause javadoc generation failure, you only need to upgrade to the latest version. The latest version is 1.2.3. Modify the version number in the build. gradle file under the project root directory as follows:

// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript {    repositories {        jcenter()    }    dependencies {        classpath 'com.android.tools.build:gradle:1.2.3'        // NOTE: Do not place your application dependencies here; they belong        // in the individual module build.gradle files    }}allprojects {    repositories {        jcenter()    }}

If you see an updated version when reading this article, you can simply change it to the latest version.

3. Add the required plug-in

Append the following code to the dependencies node in the build. gradle file under the root directory of the project:

classpath 'com.github.dcendents:android-maven-plugin:1.2'classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'

The android-maven-plugin plug-in is used to package the files required by Maven.

The gradle-bintray-plugin plug-in is used to upload the generated Maven files to Bintray.

After completion, it is shown as follows:

// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript {    repositories {        jcenter()    }    dependencies {        classpath 'com.android.tools.build:gradle:1.2.3'        classpath 'com.github.dcendents:android-maven-plugin:1.2'        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'        // NOTE: Do not place your application dependencies here; they belong        // in the individual module build.gradle files    }}allprojects {    repositories {        jcenter()    }}
4. Configure project information

Download the project. properties file and put it in your library module Directory.

The original content of the project. properties file is as follows:

#projectproject.name=project.groupId=project.artifactId=project.packaging=aarproject.siteUrl=project.gitUrl=#javadocjavadoc.name=

Details:

Project. name: project name project. groupId: Project Group ID. Generally, if your package name is com. example. test, the project group ID is com. example project. artifactId: Project ID. Generally, if your package name is com. example. project ID is test project. packaging: package type. The Android library is an aar project. siteUrl: the address of the project's official website, if not, use the address on Github, for example: https://github.com/xiaopansky/Sketch project. gitUrl: Git address of the project, for example: https://github.com/xiaopansky/Sketch.git javadoc. name: The name displayed on the home page after the generated javadoc is opened. It is usually the same as the project name.

The configuration is as follows:

#projectproject.name=Sketchproject.groupId=me.xiaopanproject.artifactId=sketchproject.packaging=aarproject.siteUrl=https://github.com/xiaopansky/Sketchproject.gitUrl=https://github.com/xiaopansky/Sketch.git#javadocjavadoc.name=Sketch

You do not need to configure the project version. The version name is automatically obtained from your build. gradle as the project version.

5. Configure the Bintray account and developer information

Download the local. properties file and put it in your library module Directory.

The original content of the local. properties file is as follows:

#bintraybintray.user=bintray.apikey=#developerdeveloper.id=developer.name=developer.email=

Details:

Bintray. user: Your Bintray user name bintray. apikey: Your Bintray API Key developer. id: it is usually your nickname developer in the open-source community. name: Your name is developer. email: your email

The configuration is as follows:

#bintraybintray.user=xiaopanskybintray.apikey=*****************************#developerdeveloper.id=xiaopandeveloper.name=********developer.email=sky@xiaopan.me

* No. Displays personal information for easy disclosure. Please forgive me

Note that you must add the local. proerties file to the ignore list to avoid personal information being submitted to Github or other websites.

6. Configure bintrayUpload. gradle Method 1: directly use the remote bintrayUpload. gradle File

Modify the build. gradle file of your library module and addapply from: "https://raw.githubusercontent.com/xiaopansky/android-library-publish-to-jcenter/master/bintrayUpload.gradle", As shown below:

apply plugin: 'com.android.library'android {    compileSdkVersion 22    buildToolsVersion "22.0.0"    defaultConfig {        minSdkVersion 7        targetSdkVersion 22        versionCode 100        versionName "1.0.0"    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }    }}apply from: "https://raw.githubusercontent.com/xiaopansky/android-library-publish-to-jcenter/master/bintrayUpload.gradle"
Method 2: Use the local bintrayUpload. gradle file after downloading

First download the bintrayUpload. gradle file and put it in your library module Directory.

Modify the build. gradle file of your library module and addapply from: "bintrayUpload.gradle", As shown below:

apply plugin: 'com.android.library'android {    compileSdkVersion 22    buildToolsVersion "22.0.0"    defaultConfig {        minSdkVersion 7        targetSdkVersion 22        versionCode 100        versionName "1.0.0"    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }    }}apply from: "bintrayUpload.gradle"

We recommend that you use the first solution, which is simple and quick. Now the configuration is complete.

7. Run the command to package and upload the package to Bintray.

Open the terminal, enter the project directory, and rungradlew bintrayUploadCommand

In addition, if you have configured Gradle locally, rungradle bintrayUploadCommand. Gradlew is an encapsulation of Gradle. If you do not install Gradle gradlew locally, it will automatically download Gradle

8. Submit your project to jcenter.

After completing all the preceding steps, you actually uploaded your project to Bintray, which is not included in jcenter. To submit the project to jcenter, you still need Bintray for review.

Log on to the Bintray website and go to the personal center. In the Owned Repositories area on the right, click the Maven icon to go to your Maven project list.

If the upload is successful, you can see your project here. Go To the project details page, click add in jcenter in THE Linked To area in the lower right corner, and enter the information in the comment input box, click send to submit the request.

Generally, the review takes 4 to 5 hours. You can wait patiently. After the review is approved, an email will be sent to you, and you will not need to review the project in the future.

9. Import your project in one sentence

After the review is passed, someone else can import your project in one sentence, for example:

compile 'me.xiaopan:sketch:2.0.0'
10. Additional addition: Keep your library module name the same as that of artifactId.

Because the path to your project's maven-metadata.xml file on Bintray isGruopId + "/" + module name.

For example, if your groupId is com. example, the artifactId is test, but the module name is library.

At this time, the project file is under the com. example. test directory, but the maven-metadata.xml file is under the com. example. library directory.

In this way, if you have multiple projects with the same groupId, The artifactId is different, but the module names are all libraries, it may conflict.

So far, I have not found a better solution. I can only keep the module name consistent with that of artifactId. If you have a better solution, please leave a message.

11. References
Android expansion series (12)-use Gradle to release the aar project to the JCenter repository and use Gradle to release the Android open source project to use Gradle in the JCenter repository.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.