六步骤开发和发布自己的Android Studio类库

来源:互联网 发布:国内域名国外空间 编辑:程序博客网 时间:2024/05/01 03:07

转载地址:
http://www.survivingwithandroid.com/2016/01/6-steps-to-develop-and-publish-android.html

Develop an open source Android library is a great experience. You have the chance to pay back, with your work, all the times you used an open source library. There are a lot of libraries that we all used and that have simplified our developer life. Develop and publish an Android open source library is, also, a great opportunity to learn.The source code is public and all other developers can check it and use it and for sure. You will get some feedbacks. As a developer, you have to be ready to get positive and negative comments, opinions, suggestions. All these help you to get a better developer. You earn, during this exciting developing process, a huge experience listening to other developers opinions, comment. So if you have an idea make it and develop it and make the code open source, you will benefit.

So if you have an idea make it and develop it and make the code open source, you will benefit.
This post summarizes the main steps to follow (or that i followed) when developing an open source Android library.

Find the idea
Find the repository
Create a website
Create a community
Publish the library
Control your repository

Step 1: Find the idea before building open source Android library
The starting point to develop an open source Android library is finding the idea, the right idea. There are a lot open source Android library and each one has its own features. Generally speaking, there are two different options:

if you have a great idea about something that is not covered then you can develop your library
otherwise you can contribute to an existing library and try to improve it.
You could have a third option: rewriting and improving an existing library adding some new features or using new technologies.

How to Use gradle to publish an Android open source library
Publish an Android jar library
To get the inspiration, you can give a look at android-arsenal.com, a great site that holds the most important open source libraries.
You can check there to know if your idea is original or there is already some like that.

Step 2: Find the repository
Once, you have the idea, it is time to find the right repository where to store the library source code. There are several options, my favourite is Github, because it is very simple to use and most important it is free.
You can create a free account as long as you manage a public repository and this is the case we are covering. Using Github, you can manage all the library developing process. To not make things too complicated, it is enough to create two branches:

master branch
dev branch
The main branch is where you store the stable code when you “release” the open source Android library source code, so that other developers can download and use it.
The dev branch is the branch under development where the code is not stable until you move it to the master branch.
The are some other interesting features that help you to manage the Android library source code like milestones and releases.

Step 3: Create the website
This step is not necessary but helps other developers to know your library and most important how to use it.
You can release such information like wiki using Github wiki-pages or you have the option to create a website hosted by Github.
In this case, you have to create a branch called gh-pages where you add your HTML/scripts files. This site should contain relevant information about the Android library, the main features, why it is different from others and why a developer should use your library.
You should add also information about the current library release and about the source code: how it is structured and how to modify it.
Do not forget to specify library dependencies if it exists.

Step 4: Create a community
Once you have released the first version of your library, you should create a community so that users and other developers can discuss topics related to your library and you can get useful information about new features. There are several ways to create and handle a community, my preferred one is using G+. Creating a G+ community is very easy and once the community is ready, invite your friends to join it. The G+ community is a great place to discuss your open source Android Libray bugs or listens to users improvements.

develop android open source community
Do not forget to link the community in the website.

Step 5: Publish the library
This is not a trivial aspect. After you developed the open source Android library, after you tested it is time to release your work. When you publish the Android library makes it available to “all the world”. The publishing process of an Android library is quite complex and requires several steps, but it makes the library easier to use.
Developers do not want to fight against the library source code to make it working. You have the choice to leave it simply as source code. Developers that want to use it, check out the code from the repository and import it into their projects.

If you want to do something more advanced you can use Sonatype repository. When the Android library is in Sonatype repository, the library can be referenced in the gradle file like:

dependencies {
compile ‘your_id:lib_name:version’
….
}

There is another option: Jitpack.io. This is an interesting solution that simplifies the publishing process and it can be easily integrated with Github. You have to create a Github release and, without much work, the library is available at maven repository. In this way the Android open source library can be referenced in gradle file.

Step 6: Control repository
One important step is controlling your repository. Once the Android library is available and users start developing projects using it, your library could have some bugs, so other good-willing developers start fixing such bugs and they create pulling request in Github.
One way to control the consistency of your repository and to avoid compiling errors when you commit changes is using Continous integration or CI. CI tools are systems that check the library source code verifying if it still compiles or not after some changes are made.
One great tool is Travis-ci. It is integrated with Github and using the same account you can create an account. Travis-ci requires you to create a build file used to guide the compiling process.
Every time the source code in Github is modified the compiling process starts and you know soon after the result.

This is my two cents worth.

0 2
原创粉丝点击