Monday, 29 May 2017

Difference between aar vs jar. And how to implement aar in Android

Although .jar and .aar files are very similar but still there are few differences between them :

1. .jar stands for Java Archive and .aar stands for Android archive.

2.  A Jar file is basically a zip-file which contains one or many class files and text files containing some sort of meta data. Jar files can be used to bundle java library containing many classes into single file. Where as .aar files are same as .jar but their also contains android stuff like source files, layouts, drawable and manifest files as a would module contains.

3. Except Android Studio the rest of the world does not know what is that thing aar file unlike jar files.

How to compile a .aar file in your android project

Add .aar file to libs folders under your module

1. Add below code snippet to your project level gradle file

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        flatDir {
            dirs 'aars','libs'
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}


2. Below code to your module level gradle

  compile(name:'name of the aar file here', ext:'aar')


Cheers!!

No comments:

Post a Comment