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'])
}