Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add an android library to the default list of libraries in Studio/SDK

So first of all, just to clear any doubts, i know how to add a library to an android project. My question here is that, i want to add a library to the list of default libraries in my android studio.

Let me explain with an example. Let's say i want to add the Glide library to my project. To do that firstly, i have to go to glide github page and then, from there i copy the compile 'com.github.bumptech.glide:glide:3.7.0' text and paste in in my build.gradle file . Then the android studio would download the library over the internet. So every time i want to use the Glide library in any of my project, i have to do this. What i want , is that, i want to include a specific libary like Glide in my Default list of libraries that are available to me

enter image description here

So Here, is where i want to include my library project, so that i can use it, in any of my projects. Thanks in advance, for reading.

like image 916
Nick Asher Avatar asked Aug 24 '16 07:08

Nick Asher


People also ask

Where should I add library in Android Studio?

To use your Android library's code in another app module, proceed as follows: Navigate to File > Project Structure > Dependencies. In the Declared Dependencies tab, click and select Library Dependency in the dropdown. In the Add Library Dependency dialog, use the search box to find the library to add.


1 Answers

There is a way to add the library to every new project/module automatically. There is a folder with templates in the Android Studio directory. Look for:

..\Android Studio\plugins\android\lib\templates\gradle-projects\NewAndroidModule\root

In this directory there is a file:

build.gradle.tfl

Modify it according to your needs.
Example:

dependencies {
    <#if dependencyList?? >
    <#list dependencyList as dependency>
    compile '${dependency}'
    </#list>
    </#if>
    compile fileTree(dir: 'libs', include: ['*.jar'])
<#if WearprojectName?has_content && NumberOfEnabledFormFactors?has_content && NumberOfEnabledFormFactors gt 1 && Wearincluded>
    wearApp project(':${WearprojectName}')
    compile 'com.google.android.gms:play-services:+'
</#if>
<#if unitTestsSupported>
    testCompile 'junit:junit:${junitVersion}'
</#if>
    compile 'com.github.bumptech.glide:glide:3.7.0'
}

As you can see, the Glide library has been added at the end.

When this file is modified, every new Android Phone & Table module will have this library included.

Of course there is nothing that prevents you from adding your own module or project template.

like image 98
R. Zagórski Avatar answered Oct 10 '22 08:10

R. Zagórski