First of all lets see the Project Structure :
The root folder contains two Project folders and two gradle files.
For now build.gradle is empty while settings.gradle :
include ':MyDemo', ':MyLibProject'
Between MyDemo and MyLibProject Project there are some differences :
1. Library Projects do not generate APK. Instead they generate an .aar package.
2. build.gradle of MyDemo contains a line
apply plugin: 'android'where for Library Project
apply plugin : 'android-plugin'
Let's have a look at MyDemo build.gradle file :
and MyLibProject build.gradle file :
We can take the first block code of each file ( which is the same ) and move it to the external build.gradle :
Android Projects have source folders ( MyDemo ) , Library Projects ( MyLibProject ) and jar file dependencies.
There are three kinds of dependencies :
2. jar file
If we choose to add a dependency like ActionBarSherlock to our project from the maven repositories we go to http://search.maven.org/ , write actionbarsherlock to the input area and click search button.
What we see is :
We can use it in our build.gradle code :
Instead of the above way we can also download the rar file, add it to the /libs folder and
compile file ('libs/actionbarsherlock.jar')
Or if we had downloaded the source code and add it like a Library Project ( File > Project Structure > Modules ) and add it to the project. Then we had to add to the build.gradle
compile project (':ActionBarSherlock')
Just keep in mind that if we add an artifact as a .jar file to a libs folder and we have the same jar file in another library folder then we are going to have a conflict. We just need to have only one copy of the jar file.
That's a good reason for you to start using the maven repository and don't just add jar files. In that case if we have added the same artifact more than once there will be no conflict.
From the Command Line. Go to the root dir of your project. Gradle works with tasks.
gradlew tasksto see all available tasks.
gradlew assembleto build the project and
gradlew installDebugto install it to the connected devices.