I am often amazed by the number of useful third-party libraries in the Android development community. For a long time, I wanted to contribute something, but I didn't know how to do it. After browsing many other articles on how to publish an Android development library, I still found that some details were missing, and all the information was in different places. So, I will walk through the process and show you how I did it. For beginners, I recommend using Android Studio to create all Android projects. Android Studio officially uses the Gradle build system. Please make sure you download the latest version of Android Studio.
Introduction to related terms Before we get started, there are some terms you should be familiar with. Project — In Android Studio, a project is a complete Android app. An Android Studio project contains one or more modules. In Android Studio, a project is similar to a workspace in Eclipse. Module – A module is a component of an app that can be built, tested, and debugged separately. A module contains the source code and resource files of an app. In Android Studio, a module is similar to a project in Eclipse. AAR – The 'aar' package is a binary distribution of the Android development library project. (AAR format) The main output of the development library project is the .aar package (which means Android archive). It is a combination of compiled code (such as jar files or .so files) and resource files (such as manifest files, res files, asset files). Maven Central Repository – A repository provided by the Maven community. It contains many commonly used development libraries. The Search Maven website can be used to browse the contents of the Maven Central Repository. The Gradle, Please website is another tool that can be used to search the central repository. If you add jCenter() to the repository configuration section of the project configuration file, Gradle will use the jCenter repository (jCenter instructions). Maven Central Repository is also often referred to as Maven Center or Central Repository. Sonatype — Sonatype's Open Source Software Repository Hosting (OSSRH) service is the primary way for project authors and contributors to publish their components to a central repository. It is a deployment hosting service for open source projects provided by the Sonatype Nexus Professional organization using the Nexus Staging Suite tool. The service is mainly used to handle deployment and verification operations, and also provides synchronization operations to deliver content to the central repository over the network. GPG - GNU Privacy Guard (also known as GPG or GnuPG), a GNU project, is a cryptographic software that follows the OpenPGP (RFC4880) standard and is a free alternative to PGP. With GPG you can encrypt (decrypt) files containing sensitive data, such as electronic health information that is protected by the privacy and security of the Health Insurance Portability and Accountability Act (HIPAA). For more information on GPG, visit the GNU Privacy Guard website. Prepare your Android development library I will use my Trestle development library as an example. In your project, you need to modify some places to prepare it for publishing to Maven Central as a development library.
Install GPG If you don't have GPG installed on your machine, you will need to download and install it. If you are using MacOSX, the installation instructions are here. If you have never used GPG - first, create a GPG key:
If you're unsure how to answer the questions when you create your GPG key, this guide (Creating an encryption key) can help. Next, find your key ID:
The first line will be something like pub XXXXX/YYYYYYYY <date>. Remember, the 'YYYYYYYY' part is your key ID. Now, publish your key:
You can of course use other key servers, and you can also confirm whether your key has been published by running the following command:
To get your library listed on the Gradle, Please website (and to make it easier for others to reference your library), please upload your project to Maven Central. The easiest way to upload a project is to use Sonatype. Sonatype
I created a GitHub repository for my Trestle project. So the fields I filled in on the new issue looked like this: Group Id : com.github.<github_username> Project URL : https://github.com/<github_username>/<project_name> SCM url : https://github.com/<github_username>/<project_name>.git Username : <sonatype_username> Already Synced to Central : No Note: I added brackets as placeholders around the fields you need to fill in. You will need to replace them with the appropriate values. When you are ready to submit an issue, the details of the issue should be similar to the screenshot above. After you submit it, Sonatype will take 2 working days to process your issue. Then, you will receive a confirmation email informing you that your configuration is ready and you can publish your open source library. Don't deploy your open source repository until you receive an email indicating that your ticket is OK. A common mistake for new projects is to deploy too early. This will mistakenly make your artifacts available in a repository for everyone to access. Finally, if your component is already in the central repository, please add the following information to your ticket and refer to this article on how to migrate to OSSRH. Modify the ~/.gradle/gradle.properties file on your machine to include the following:
When you publish the repository, the authentication information is provided in the gradle.properties file. Please make sure to provide the correct nexus username and password (that is, the Sonatype username and password), otherwise you will get an unauthorized 401 error. NOTE: If you have published a repository before, you do not need to create a new issue in JIRA (Sonatype). There is one JIRA issue for each top-level groupId. You should already have all the permissions you need to deploy any new artifacts to your groupId or subordinate groups. Syncing with the central repository follows a top-down process, so any releases from subordinate groups will be automatically synced. When you publish new components, you do not need to tell Sonatype because there is nothing for Sonatype to configure or check when you sync the repository. Sonatype will only post a twitter message the first time it syncs. release Once you are ready to publish your development library, in Android Studio, open the Gradle view on the right, under Tasks > upload, click uploadArchives, which will upload your development library to the Sonatype Staging Repositories. On the Sonatype Staging Repositories page, log in to your Sonatype account, find your 'staging' repository, it should be at the end of the list, select it and press the 'Close' button. Closing a repository actually means you are preparing to publish it. If everything went well – you should see an activated 'Publish' button. You may need to refresh the page. Press the Publish button. Please read the help documentation about managing repositories with Nexus. If this is the first repository you have published, go back to JIRA and post a comment in JIRA that you have improved your repository, if it is not the first, there is no need to tell Sonatype that you have improved your repository. Then, you should receive a reply message from Sonatype saying that your repository will be ready in 10 minutes and will be synchronized to the Maven Central Repository in the next few hours. After a few hours, it will be displayed on the Gradle, Please website. Using your development libraries For other developers to use your development library, they need to add a dependency in the build.gradle file of the Android project, as shown below:
Special Thanks Many thanks to Chris Banes, Jonathan Le, Serge Zaitsev, and others who posted on the blog, whose articles helped me navigate this complex process. My development library QuickReturn — https://github.com/lawloretienne/QuickReturn Trestle — https://github.com/lawloretienne/Trestle ImageGallery — https://github.com/lawloretienne/ImageGallery |
<<: Agora.io launches AMG Voice, a real-time voice service for mobile games
>>: Detailed explanation of Android Transition Framework --- super cool animation framework
Will Luckin Coffee become the next ofo? Luckin Co...
Leviathan Press: I have heard before that the rea...
When Jobs decided that Apple needed its own smart...
From oral messages, letters, telecommunications t...
There is a saying on the Internet: "People w...
"Ele.me received $1.25 billion in financing ...
[April 10, 2021] Emma and Shenzhen Satellite TV j...
Yesterday was the beginning of autumn, and “the f...
The cold December is here, and there are still ma...
For SEO website optimizers, knowing how to build ...
Two days ago, I saw a colleague coming out of the...
Author: Professor Guo Tuankui, Department of Onco...
Produced by: Science Popularization China Author:...