Android-library-publish-to-jcenter is a project that helps Android developers publish AAR libraries to jcenter. Android-library-publish-to-jcenter has packaged the scripts that need to be written, we only need to configure the relevant properties to release our project to Jcenter within 5 minutes (not including the audit time)
1. Register Bintray account (Portal)
Bintray is a jcenter custodian, so you must register a Bintray account and write down your username and API key after registering your account.
After landing in the top right corner of the home page click on the user name to enter the personal page, and then click on the user name under Edit to enter the personal information editing page, next click on the left side of the list of the last API key
Click the Copy button indicated by the rightmost arrow to copy your API Key
2. Check the Android plugin version
First you have to check the version of your Android plugin, because the 1.1.0 version has a bug that will cause the build Javadoc to fail, so you just need to upgrade to the latest. Currently the latest version is 1.2.3, in your project root directory under the Build.gradle file to modify the version number, as follows:
sub-projects/modules.buildscript { repositories { jcenter() } dependencies { ‘com.android.tools.build:gradle:1.2.3‘ not place your application dependencies here; they belong // in the individual module build.gradle files }}allprojects { repositories { jcenter() }}
If you have an updated version of this article, change it directly to the latest version.
3. Add the required plugins
Append the following code to the dependencies of the Build.gradle file in the root directory of your project:
‘com.github.dcendents:android-maven-plugin:1.2‘‘com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0‘
The Android-maven-plugin plugin is used to package the files required by Maven.
The Gradle-bintray-plugin plugin is used to upload the required files for the generated maven to the Bintray
This is done as follows:
sub-projects/modules.buildscript { repositories { jcenter() } dependencies { ‘com.android.tools.build:gradle:1.2.3‘ ‘com.github.dcendents:android-maven-plugin:1.2‘ ‘com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0‘ 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 contents of the Project.Properties file are as follows:
#projectproject.name=project.groupId=project.artifactId=project.packaging=aarproject.siteUrl=project.gitUrl=#javadocjavadoc.name=
Detailed
- Project.name: Project Name
- PROJECT.GROUPID: Project group ID, usually if your package name is Com.example.test, then the project group ID is com.example
- Project.artifactid: Project ID, usually if your package is named Com.example.test, then the project ID is the test
- Project.packaging: Package type, generic Java is jar, then the Android library is AAR
- Project.siteurl: The address of the official website of the project, if not, use the address on GitHub, for example: Https://github.com/xiaopansky/Sketch
- Project.giturl: The git address of the project, for example: Https://github.com/xiaopansky/Sketch.git
- Javadoc.name: The name of the generated Javadoc when the home page is opened, usually the same as the project name
Complete the configuration 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 and will automatically get the version name from your build.gradle as the project version
5. Configure Bintray account and developer information
Download the local.properties file and put it in your library module directory
The original contents of the Local.properties file are as follows:
#bintraybintray.user=bintray.apikey=#developerdeveloper.id=developer.name=developer.email=
Detailed
- Bintray.user: The user name of your Bintray
- Bintray.apikey: your Bintray API Key
- Developer.id: Usually your nickname in the Open source community
- Developer.name: Your Name
- Developer.email: Your e-mail
Complete the configuration as follows:
#bintraybintray.user=xiaopanskybintray.apikey=*****************************#developerdeveloper.id=xiaopandeveloper.name=********[email protected]
* The display of personal information is not anti-convenient disclosure, but also forgive me
Note To add the Local.proerties file to the Ignore list to avoid being submitted to GitHub or other websites to disclose personal information
6. Configure Bintrayupload.gradle Method 1: Use remote Bintrayupload.gradle files directly
Modify your library module's Build.gradle file, at the end of the add apply from: "https://raw.githubusercontent.com/xiaopansky/android-library-publish-to-jcenter/master/bintrayUpload.gradle" , as follows:
apply plugin: Com.android.library ' android {compilesdkversion 22 buildtoolsversion "22.0.0" defaultconfig {minsdkversion 7 targe Tsdkversion 22 versioncode 100 versionname "1.0.0" } Buildtypes {release {minifyenabled false proguardfiles ge Tdefaultproguardfile ( ' proguard-android.txt ' ), }}}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, then modify your library module's Build.gradle file, at the end of the add apply from: "bintrayUpload.gradle" , as follows:
‘com.android.library‘android { 22 "22.0.0" defaultConfig { 7 22 100 "1.0.0" } buildTypes { release { false proguardFiles getDefaultProguardFile(‘proguard-android.txt‘‘proguard-rules.pro‘ } from"bintrayUpload.gradle"
I certainly recommend that you use the first solution, which is simple and quick, so the configuration work is all over.
7. Execute the command package and upload to Bintray
Open the terminal into the project directory and execute the gradlew bintrayUpload command.
Also, if you have gradle already configured locally, the gradle bintrayUpload command can be executed. Gradlew is a gradle layer package, if you do not have Gradle installed locally gradlew will automatically download Gradle
8. Request to submit your project to Jcenter
After all the previous steps have actually just uploaded your project to Bintray, and not included in the Jcenter, to submit to Jcenter also need bintray audit.
Login to the Bintray website, enter the personal center, and click on the Maven icon in the owned repositories area on the right to enter your MAVEN project list.
If the upload is successful, you can see your project here, enter the project details, in the lower right corner of the linked to area click Add in Jcenter, and then in the Comment input box, fill in the information, and finally submit the request can be
Generally, the audit takes 4-5 hours, waiting patiently on the line, the audit will send you an email to notify you, and later update the project will not need to review.
9. Import your project with one sentence
When the audit is passed, others can import your project in one sentence, for example:
‘me.xiaopan:sketch:2.0.0‘
10. Additional additions: Keep your library module in the same name as Artifactid
Because the path to the Maven-metadata.xml file of your project on Bintray is gruopId+"/"+module名称 .
For example, your groupid is Com.example,artifactid is test, but the module name is the library.
This time the project file is in the Com.example.test directory, but the Maven-metadata.xml file is in the Com.example.library directory.
This way, if you have multiple items GroupID, Artifactid is different, but the module name is the library, it may conflict.
So far I have not found a better solution, only to let the module name and Artifactid consistent, if you who have a better way, welcome message exchange.
11. Reference Articles
- Android Outreach Series (12) – Use Gradle to publish AAR projects to the Jcenter warehouse
- Use Gradle to publish Android open source projects to Jcenter
- Publish projects to the Jcenter warehouse using Gradle
- Android project packed into Jcenter's pit
Android-5 minutes to publish Android library project to Jcenter