Publish an open source library to the Jcenter Central Library using Android Studio

Source: Internet
Author: User

First register an account in https://bintray.com, log in and then get an API Key from its background

Add dependencies to the Build.gradle file in your project's root directory, and the final file content becomes like this.

buildscript { repositories { jcenter() } dependencies { classpath ‘com.android.tools.build:gradle:1.2.3‘ classpath ‘com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0‘ classpath ‘com.github.dcendents:android-maven-plugin:1.2‘ }}allprojects { repositories { jcenter() }}

Create a new Gradle file under the root directory named Bintray.gradle, which reads as follows

Group = Proj_groupversion = Proj_versionproject.archivesbasename = proj_artifactidapply Plugin:' Com.jfrog.bintray 'Apply plugin:' Maven-publish 'Task Sourcesjar (type: Jar) {from android.sourceSets.main.java.srcDirs classifier =' Sources '}task Javadoc (type: Javadoc) {Source = Android.sourceSets.main.java.srcDirs Classpath + = configurations.compile Classpath + = Proje Ct.files (Android.getbootclasspath (). Join (File.pathseparator))}task Javadocjar (type: Jar, Dependson:javadoc) {classifier =' Javadoc 'From Javadoc.destinationdir}javadoc {options{encoding"UTF-8"CharSet' UTF-8 'AuthortrueVersiontrueLinks"Http://docs.oracle.com/javase/7/docs/api"Title Proj_artifactid}}artifacts {Archives Javadocjar Archives Sourcesjar}defPomconfig = {licenses {license {name"The Apache software License, Version 2.0"Url"Http://www.apache.org/licenses/LICENSE-2.0.txt"Distribution"Repo"}} developers {developer {ID developer_id name developer_name email DEVEL Oper_email}}//There are quotation marks, and there is a space, otherwise can not generate dependency, mainly here is the dependencies is not build.gradle dependencies, and Gradle will treat him as his own dependencies    "Dependencies"{dependency{GroupId"Com.alibaba"Artifactid"Fastjson"            "Version" "1.2.6"            //With dependencies}}}publishing {publications {Mavenjava (mavenpublication) {Artifactid Proj_artifactid pom{Packaging' AAR '} pom.withxml {defroot = Asnode () Root.appendnode (' description ', proj_description) Root.children (). Last () + Pomconfig}}}}bintray {Properties p roperties =NewProperties () properties.load (Project.rootProject.file (' Local.properties '). Newdatainputstream ()) user = Properties.getproperty (' Bintray_user '); Key = Properties.getproperty (' Bintray_key '); configurations = [' Archives '] Publications = [' Mavenjava '] Publish =truepkg {repo =' maven 'name = Proj_name desc = proj_description Websiteurl = Proj_websiteurl Issuetrackerurl = Proj_issuetra Ckerurl Vcsurl = Proj_vcsurl licenses = [' Apache-2.0 '] Publicdownloadnumbers =true}}

Note that if your project relies on a third-party library, you also need to join, such as here I quoted the Fastjson, in the corresponding location to add the dependency code, like this, the only thing to note is that dependencies and version need to be enclosed in quotation marks, And leave a space behind, because these two keywords will be executed by default, here the opportunistic to solve the problem

"dependencies " {    dependency{        "com.alibaba"        "fastjson"        "version ""1.2.6"    }}

Then add the code that applies the file to the last side of the Build.gradle under your library module, and note that the build.gradle here is under the module instead of the root directory.

from‘../bintray.gradle‘

Finally, the corresponding variables can be configured. Add attributes to the Gradle.properties file in the root directory, using the

Compile ' com.android.support:appcompat-v7:22.2.0 '

Do a sample

proj_group= here to GroupID, like Com.android.support. proj_version= here to the library version, such as 22.2.  0  proj_name= here into a library name, like AppCompat. proj_websiteurl= here to GitHub address, like Https://github.com/android/appcompat proj_issuetrackerurl= here to issue address, like Https://github.com/android/appcompat/issues. proj_vcsurl= here to version control landlords, such as Https://github.com/android/appcompat.git proj_description= Here to change the description of the library. proj_artifactid= here to the library, like Appcompat-v7. developer_id= here to developer ID, such as developer_name= here to the developer name, such as Android developer_email= here to the developer email, such as [EMAIL protected] 

And then in the project root local.properties add two important attributes, one is a previously registered account, one is the account background API key, this file does not add version control, exists locally.

BINTRAY_KEY=你的API KEYBINTRAY_USER=你的用户名

After using Android studio to build the Gradle task, add the above content and your gradle will have a few more tasks. Click Gradle on the right side of Android studio

After your library file expands there will be a publishing/bintaryupload task, double click to execute it, if there is no error, you can find in your background has been uploaded. Here to avoid errors, before executing this task, first execute three task to generate the necessary files, That is, the Javadocjar and Sourcesjar in other and the generatepomfileformavenjavapublication in publishing, to generate Javadoc.jar, Sources.jar and Pom.xml files, make sure the build successful and then execute the bintrayupload task under publishing so that it is uploaded to your backend.

Click on the package you uploaded and go to the admin page

Click Add to Jcenter in the lower right corner, and submit for review directly. Here I have passed the audit, so the display is link to and other information. After the approval, you can directly in the Gradle quote, take me this project is

compile "cn.edu.zafu:corepage:0.0.1"

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Publish an open source library to the Jcenter Central Library using Android Studio

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.