Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference Between Library & Library Project & External Libraries

In the Android Studio IDE you can add a .jar file. You can also add entire projects that are 'Library Projects'. And there are also the Android libraries (from Gradle) added as External Libraries.

.jar Jars

Library Project Library Project

External Library External Libraries

I get that .jars are just that. But then how come other libraries (Library Projects) need to get added that have entire build files of their own (like gradle, res, src etc). And further complicating my understanding, the Gradle downloaded ones are added as 'External Libraries' and those have .jar files and a res folder.

Could you explain why libraries can be added as .jar, entire projects, or as external libraries?

like image 265
Aggressor Avatar asked Nov 04 '15 17:11

Aggressor


People also ask

What is diff between library and framework?

Libraries provide developers with predefined functions and classes to make their work easier and boost the development process. Framework, on the other hand, is like the foundation upon which developers build applications for specific platforms.

What is the difference between a library and a service?

The differences So the library is part of the application and runs on the same machine as the application. A library is accessed via function calls. In contrast, a service has its own infrastructure. This means it has its own machine, but also logging, monitoring, alerting, potentially an on-call team to fix issues.

What is difference between library and framework in JS?

The main distinction between a framework and a library is that a framework inverts program control. It informs the developer of what they require. A library, however, does not. Instead, a programmer calls the library when and where he needs it.

What is the difference between library and framework in react?

In this tutorial, we'll learn the differences between them, as well as explore various aspects of each. We can say that a library implements a particular function. Some examples of popular libraries are React, and JQuery. We can define a framework as a collection of libraries implementing a particular methodology.


1 Answers

Could you explain why libraries can be added as .jar, entire projects, or as external libraries?

You have different possibilities, because you can have different cases. Often the library is built by other team and you can't decide how it is distributed.

  • You can have a own library or a fork locally. In this case you have the code and you can add this library as a module

In this case just add in the module/build.gradle:

apply plugin: 'com.android.library'

and add the dependency in the main project like:

dependencies{
  compile project(':module')
}
  • You can use a maven dependency. In this case someone uploaded the library in a maven repository.
    Currently it is the best solution in my opinion.

In this case just add a dependency in your project

dependencies{
  compile 'group:name:version'
}

This dependency can be a aar file, but also a jar file.
Also you can publish in a public or private maven your own libraries.

  • You can add an aar file in your project

In this case define your flat repository:

repositories {
    flatDir {
        dirs 'libs'
    }
}

and add the dependency:

dependencies {
   compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
 }
  • You can add a jar file in your project

In this case usually you can put all jars in the libs folder and add the dependency:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}
like image 70
Gabriele Mariotti Avatar answered Sep 29 '22 18:09

Gabriele Mariotti