Want to write your first Android Library?

Nishchal Raj
MindOrks
Published in
4 min readOct 24, 2018

--

Writing an android library is not that complex once you came up with the idea what the library will do or contain as a feature that no one serves. So the very first step is thinking or getting an idea to write an unique library. This reading will let you know the easiest steps to write your own first android library.

Watching everyone getting their own library published with the unique features as they describe, I was amazed and inspired at the same time to do the same and started researching about the ways to create my own library. Some of those ways were complex as I was a beginner in writing library, but always had a thought how I could use it as we all have worked on so many famous libraries. I came up with my easy steps to write my first android library and published it too and all of this within 1 week. And want every beginner to know the steps.

Let’s get started with the steps. :)

Step 0: Yes, zeroth step because this is most basic. Learn what is library and how it functions? What are the necessary files to be included and how it helps improve the functionality of any application it is used in. Here’s a Medium link, to get you only know how to get started and publish it, because these are basics everyone should know, then return here to know more.

Step 1: Look out for the simple libraries i.e. those which don’t have the complex functionality and provide some smooth features (like the following) and learn from them — Ticket View, Custom Android Toast, Range Time Picker Dialog and there are many more you can explore.

Step 2: After the first two steps, I hope you have gained knowledge about the basics of android library development. Now think about the functionality your library will provide. Yes, there should be something your library should serve as its interesting feature to stand out from the rest of the crowd of libraries. Keep a note of the functionality (like it will change its color, it will include a text in it, it will change its size, it will change its height, it will return the default attributes). For example, consider the functions this library (Dropdown TextView) has.

Step 3: Consider “Creating The Android Library” from the link in Step 0 to create the library files only. Don’t publish it or do anything more, else you may break the easy flow we are going on with.

Step 4: If your library is going to contain some default layouts (like it’s here and here) which will get embed in the application layout when library will be included using com.android.<library_name> or any other format. then you need to design the xml structure (layout) carefully with proper default attributes you want your library to be included in as. Please consider the examples in the link provided in this step.

Step 5: This step is going to be the most important, as in this we are talking about the main functionality file of your library i.e. libraryname.java or libraryname.kt . For example look at the main files of PRDownloader, PasswordStrengthBar and Collapsible Calander. Include the initialization (of all the layout elements, in the xml) with their proper definitions and declarations. Then move on with the functionality you noted in Step 2 . Make proper returnable functions i.e. use int, string, boolean or void or any other according to the need. Note: Keep the function’s access specifier very accurate i.e. don’t allow public for the functions that aren’t needed to be used by the other users.

Step 6: Remember to comment the methods’ use or the regular commenting habit should be applied so that the user can get to know the use of the functionality of the methods used and other important stuffs.

Step 7: It will be good if you create an app (sample application) to show the use of the library you created and you can do this in the same package. Just use the app file to develop an application to explain the uses. By the way, this will also help you keep track of your library’s working and proper functioning.

Step 8: Last but not the least, follow the “Publishing the Android Library” part in the link on Step 0.

I hope you have successfully created and published your very first android library and with cool new features which are not there in the market. No need to stop here, keep improving the library and keep looking for issues and resolve it. Prepare a beautiful readme.md and use a proper licensing and let the developers use it.

I followed the same steps written above and created my very first android library: PasswordStrengthBar. I would love if it ever fulfills your need and like to know your thoughts on it.

Keep developing secure stuffs. :)

--

--

Nishchal Raj
MindOrks

Co-Founder @ Paisa App | Technical Speaker @ ALCCalabar - Google I/O '22 Extended-BLRKotlin #30 | Ex-GDSC Lead | Writer | Researcher | @thenishchalraj