1

I want to know that which is the best way to use external libraries in android studio and workflow of it. Either to compile them directly in build.gradle and using its functionalities or copy the whole external library in my project.

Some doubts:- If i am using first way then how it works, is it connected to internet or i can have problems in future if that library is deleted from github or somewhere else

And if i am using second way then it is true that it will increase the size of my apk but it will not cause any problem in future because it is secured in my project and there is no chance of losing it as in the first way it can be deleted. Please correct my doubts because i am not sure what is happening there?

2 Answers 2

1

The best way to use an external library in your project is the first one. Just add the dependency in build.gradle. There is no insecurity in adding it like this. You will have to be connected to the Internet for the first time you build your project. It will download and include the jar in your project. After this even the dependency is deleted from git, your project will work well.

Sign up to request clarification or add additional context in comments.

3 Comments

Pleasure helping indian on SO...india rocks😊😊😊
But some one is saying that it is necessary to download for first approach but what here "downloaded " means whole library of something else and if i will download it where it is saved in then ....
It downloads only necessary classes which you have used in your code. Which eventually does not increase size of your apk.
1

I want to know that which is the best way to use external libraries in android studio

Both of them has a pros and cons:

Using the Build.gradle approach:

Pros:

  • Easy to add since its just adding a single line of code in your Gradle.

  • Easy to update (Just change the version number and click sync gradle).

Cons:

  • Needs Internet
  • If removed from Mavencentral or Jcenter, you wont be able to access it. (unless already downloaded)

Using the Library/Module itself:

Pros:

  • You have a hard copy and worry no more for hosting removal.
  • Decompilable codes : meaning you can change its behavior just to learn how it works behind the hood.

Cons:

  • Needs a little effort in importing.

And if I am using second way then it is true that it will increase the size of my apk

Adding Librarie(s) to your project will surely increase the APK, it is inevitable.

12 Comments

i am confused... u r saying that if i use bulid.gradle approach then it needs internet but it does not require internet when i use it in my mobile and u also said that i won't be able to access it unless already downloaded. So what here "downloaded" means whole library if it is than it will become second approach or something else u r talking abt...
You will need an internet when you build the project at first time since it will download the Library from a special repository hosting. I think you are just confused on Building Project from Running the project.
can i see that downloaded library
It is located in a special directory created by Gradle, I forgot the path.
okk...So how can i be sure that it is downloaded and in future it will not cause any problem if it is deleted from hosting side
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.