Android Library upload to jcenter warehouse practice

Source: Internet
Author: User
Tags jfrog jcenter

Objective

During this time, I studied the Jcenter warehouse, which was not too concerned about the development of the app before, in the actual development, it is usually used by third-party developers to upload to the Jcenter library. And how do the libraries or plugin that we use publish to jcenter and let me use them? What should we do if we want to develop a library or a plugin? With these questions, I have made the following practices around it:

    • Android Library upload to jcenter warehouse practice
    • Gradle Plugin Development Practice-upload APK file to bugly

I will be two blog to share my practice process, this is the introductory article, mainly to tell you how to create an Android library and upload to Jcenter, very simple, I believe you read this article later want to publish an open source library to the vast number of developers use is no longer a problem.

Concept popularization

What is Jcenter?
Jcenter is a maven repository maintained by bintray.com. In general, we will define the warehouse used:

{        jcenter()    }

What is maven warehouse?
You can understand the file server that holds our library.

When we use some open source libraries, we may see that the Build.gradle in the project root directory has the following configuration:

{    repositories {        mavenCentral()    }}

What is mavencentral again?
I'm so messed up, I don't want to talk. But you still take the question to Google, can search the question we do not say hello?
All right, just say the answer. Mavencentral and Jcenter like, are maven warehouse, just store the place is not the same, do not guess, they have no relationship, there is a period of time Android default warehouse is Mavencentral, but later because it is not very friendly to developers, The default warehouse is replaced with Jcenter.

For more detailed instructions, you can refer to the following articles:
Http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0623/3097.html

Register Bintray Account

If you want to publish your library on Bintray, you have to create an account, and it is recommended that you sign in directly with your GitHub account, so that your open source repository can find the appropriate source on GitHub, and if you don't want to make it public, create another account.

Once you've signed in, you'll be able to see some famous warehouses in Bintray, such as the homebrew that our developers often use.

Create a Package

Here is an example of creating a Myutils package, as shown in:

OK, this time you create the package, you can prepare the library we developed, and then upload to the Maven warehouse, continue to look at the following steps.

Create an Android Library

Create a new Android project, then new module, select the Android library, the project structure is as follows:

Here I'm just creating a simple class for the demo:

Application Bintray Plug-in

If you want to upload the library through the Bintrayupload command, you must refer to the appropriate plugin, configured as follows:

{        classpath ‘com.android.tools.build:gradle:2.0.0‘        classpath ‘com.github.dcendents:android-maven-gradle-plugin:latest.release‘        classpath ‘com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6‘    }

Then in our library project the Build.gradle reference plugin, as follows:

‘com.android.library‘com‘com.jfrog.bintray‘

One of the com.android.library is the Android plugin, which indicates that it is an Android library.

After the app succeeds, you'll see the plugin-generated task as shown in:

With this task, we can upload our library to the Maven repository, and now we still have to finish our configuration.

Build.gradle Configuration

We need to configure our corresponding information in the Build.gradle of the Library project, here is the sample code:

Apply plugin:' Com.android.library 'Apply plugin:' Com.github.dcendents.android-maven 'Apply plugin:' Com.jfrog.bintray '//This version is differentiated from the Library edition, so remember to change that version when we need to update the libraryversion="1.0.0"Android {Compilesdkversion +Buildtoolsversion"23.0.3"Resourceprefix"Devilwwj_"Defaultconfig {minsdkversion9Targetsdkversion +Versioncode1Versionnameversion} lintoptions {Abortonerrorfalse} buildtypes {release {minifyenabledfalseProguardfiles Getdefaultproguardfile (' Proguard-android.txt '),' Proguard-rules.pro '}}}dependencies {Compile Filetree (dir:' Libs ',include: [' *.jar ']) Testcompile' junit:junit:4.12 '}def SiteURL =' Https://github.com/devilWwj/Android-Tech '     //Homepage of the projectdef giturl =' Https://github.com/devilWwj/Android-Tech.git '  //git repository URLGroup ="Com.devilwwj.library"//Maven Group ID for the artifact, generally fill in your unique package nameInstall {repositories.maveninstaller {//This generates pom.xml with proper parametersPom {Project {packaging' AAR '               //Add your description hereDescription' My utils for test 'Name' Android commonly used utils ' //Project DescriptionURL SiteURL//Set your licenseLicenses {license {name' The Apache software License, Version 2.0 'Url' Http://www.apache.org/licenses/LICENSE-2.0.txt '}} developers {developer {//Developer InformationId' your_id 'Name' YOUR NAME 'Email' YOUR EMAIL '}} SCM {connection Giturl developerconnection Giturl URL SiteURL}}}}}task Sourcesjar (Type:jar) { fromAndroid.sourceSets.main.java.srcDirs classifier =' Sources '}task Javadoc (type:javadoc) {options.encoding =' UTF-8 'Source =' Src/main/java '}task Javadocjar (Type:jar, dependson:javadoc) {classifier =' Javadoc '     fromjavadoc.destinationdir}artifacts {Archives Javadocjar archives sourcesjar}properties Properties =NewProperties ()//Load Local configurationProperties.Load(Project.rootproject.file(' Local.properties '). Newdatainputstream ()) bintray {user = Properties.getproperty ("Bintray.user") key = Properties.getproperty ("Bintray.apikey") configurations = [' Archives '] pkg {repo ="maven" //posted to Bintray in the warehouse, the default account has four libraries, we upload here to Maven libraryName ="Myutils" //Publish to Project name on BintrayWebsiteurl = SiteURL Vcsurl = Giturl licenses = ["Apache-2.0"] Publish =true}}

You also need to define two lines of code in Local.properties:

bintray.user=YOUR_BINTRAY_USERNAMEbintray.apikey=YOUR_BINTRAY_API_KEY

The Bintray is your user name and Apikey, which can be found in your profile.

After the configuration is complete, we can execute the bintrayupload command to upload our library to Bintray, either directly execute the task or typing the following command at the command line:

gradlew bintrayUpload

If the upload is successful, you will see your library on the Bintray page, such as the Myutils library that I uploaded via the command:

This time you have implemented uploading the library to the Maven repository via the Gradle script, you can verify the following locally, requiring the Build.gradle configuration in the root directory:

{    repositories {        jcenter()        maven {            url ‘https://dl.bintray.com/devilwwj/maven/‘        }    }}

This allows us to access the library uploaded to Maven in the project configuration:

After compiling successfully, you can see the library we downloaded from the MAVEN repository at external libraries:

But if you want other developers to use it directly, you need to upload it to jcenter without having to configure MAVEN's address.

Upload to Jcenter

After you've done this, you just wait for the Bintray team to approve, and then the other developers just need to configure a single line of code to use.

Summarize

about using Gradle Upload Library to Jcenter practice basic so, in practice before also refer to a lot of articles, but the process is basically similar, we can compare, you follow these steps to practice, see if you will encounter some pits, trample pits and pits process is the accumulation of your experience, Why I want to know these things, I used to develop the app is not too concerned about these, but from the application developers to the SDK developers, from the use of the wheel to create the wheel of the transformation, I need to focus on these, from know what to why and how to do, this is very important for us to learn knowledge deeply.

Android Library upload to jcenter warehouse practice

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.