How to Improve Coding Time Using Library Project

How to Improve Coding Time Using Library Project

A library is nothing but a set of files, which will be used in other projects, and it can not be directly runnable. We can consider Facebook SDK or Google SDK as a library.

Table of Content

Why do we need a library?

This question must arise in everyone's mind because no one wants to waste his/her time developing a thing that is never useful. Is it really a waste of time or an investment for the future?

Let me give you a real example that I have currently seen. There is a client for whom we have developed one application (ex. Chat app). The application is successful, and the client is happy with our work. Now client needs another chat app with only a color change, or we can say that another app needs a chat function within.

Now we have two options.

Option 1: We can make standard source code for both apps (It works as a library)

Option 2: we can just copy and paste chat functionality into another app.

We can use any approach for this app because, at this time, it doesn't have any effect on efficiency.

Now let's see the future; after the success of the second app, the client wants the third app with minor updates. We can again clone the app and does the same thing. Every clone and update is consuming time and impacts the efficiency of experts. But let's see how much it can be flexible through the use of a library.

Benefits of library

  • Reusability - Clone the app is not a good solution because it is not reusable. Once you have created common module for chatting and published it as a library, anyone and everyone can plug the library in and use it without affecting other code or package-related issues. It can be reusable as many times as we want.
  • Time-Saving - Is it time-saving or not? We need to create one standard module for all apps. So if there are any changes, we need to worry about just one place. If we add new features, all connected apps will be updated automatically.
  • Easy Maintenance - Maintaining one codebase is easy and fast than maintaining multiple apps. It is easy to maintain as we can update or modify the code from one place.
  • Easy debugging and Testing - A library makes your debugging and testing easy. We have only one codebase, so we need to test only once.
  • Faster build time - For example, the client wants to develop an app that we divided into 4 part modules. On-the-other hand, we already had a library for 3 desired modules. So, we need to work on only 1 module as others are ready to use with us as a library. This way, we can quicken the app build time.

contact us for android application

How does the Library Work?

Library Module > App Module > App

We can create a library as another module in the same project or publish our library separately and import it into our project. We need to pass a few parameters if the library requires them, and we are ready to rock. It sounds simple right? But it is not as simple as it sounds. It takes time to set up a library.

"SharedPreference” wrapper in Android or "DateTimeFormatter" library is commonly helpful in almost every app.

Step to Create Library Module for Android

It is like creating a new project. One can create a new module from File > New > New Module.

library module

Check out this image that will help you create a new module as a library module.

library module menu

Now what we have to do is write code inside the library module. Just for the demo, create “Helper.kt” object file. write a function that will log details:

fun writeLog(logText: String)
{
var modifiedLogText = "$currentTime - $logText"
if(debugBuild)
	{
	Log.d("AppLog", modifiedLogText);
	} else 
	{
	writeLogInFile(modifiedLogText);
	}
}

Now it is time to use it in a project, add module dependency to the current project module, and we are ready with our library, which will log text in our format. This module is easy to copy-paste into any project, or we can also publish this library and use it just like a material library.

Example of single-line code that we can use to import the library once it is available on some common platforms like GitHub.

  • Implementation 'com.google.android.material:material:1.5.0'
  • implementation 'com.myownlibrary:1.0.0'

Conclusion

It is better to work once and use the outcome each time required, rather than cloning every time. We can save time for development by creating a library module or creating a utils file. Never copy and paste inside the same project or similar project. Always look for space where you can just put that code and use it repeatedly.

Hire android developers from The One Technologies. They do smart work with hard work and deliver excellent output in less time.

About Lalit Jadav

lalit-jadav-bioLalit Jadav started his career journey in 2014 as an android developer. He chose android development because it is a trendy field and you need to update yourself every day. He is currently working as a team leader in our android development department.

He has developed applications for various industries like education, banking, and retail. He wants to become a thought leader in android app development by sharing his valuable knowledge.

Certified By