Adding an external library in Android Studio is a very common thing but still, most beginners or freshers find it difficult to do. So let’s learn how to add any external library to our Android Studio project and the pros & cons associated with it.
Let’s discuss three ways of adding an external library as follows:
It is very easy to add Gradle dependency. Most of us are familiar with this method as it is a common way and recommended too. Suppose you want to add Picasso to your project then you can add Gradle dependency as mentioned below to your project in build.gradle at the app level inside the dependencies block.
1 |
implementation 'com.squareup.picasso:picasso:2.71828' |
In the above implementation, 2.71828 is the latest version of the library. It will be different for different libraries and you can get it from respective Github repositories or release note’s pages.
Pros: If we need the updated version of the library we can directly see the latest version over its Github repository and replace it with the existing one and our library will be updated.
Cons: If you want to change any kind of code in the existing library then it’s not possible as it is read-only.
In some cases, we don’t get the Gradle dependency of the library. Instead, we get only the .jar/.aar file. In such case you can follow the below steps:
Pros: I don’t see any pro for this. As we only need to add any .jar/.aar dependency if the library provider doesn’t have any other way to do.
Cons:
There can be a situation when we need to modify the library code according to our requirement then in that case we can follow this method.
Pros: You can modify the code according to your requirement.
Cons: Getting the updated version of the library can be difficult since we are making code changes here.
So these are the three ways of adding any external library to the Android Studio project. Hope this will help you guys.
Thanks.
Subscribe to us and get the latest news.