Home

Awesome

fat-aar-android

license Maven Central

I am no longer engaged in research and development, so the project will not be updated and maintained.<br> You can try to use the following steps to reference the remote plugin. If it doesn't work on the new version of gradle, you can fork or download this project to modify it, the code of this project is not very complex.

P.S. Hope Google can support this damn feature as soon as possible.

The solution of merging aar works with AGP 3.0 and higher. (Tested in AGP 3.0 - 7.1.0, and Gradle 4.9 - 7.3)

Getting Started

Step 1: Add classpath

Add snippet below to your root build script file:

For Maven Central (The lastest release is available on Maven Central):

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.github.kezong:fat-aar:1.3.8'
    }
}

Step 2: Add plugin

Add snippet below to the build.gradle of your main android library:

apply plugin: 'com.kezong.fat-aar'

Step 3: Embed dependencies

Declare embed for the dependencies you want to merge in build.gradle.

The usage is similar to implementation, like this:

dependencies {
    implementation fileTree(dir: 'libs', include: '*.jar')
    // java dependency
    embed project(path: ':lib-java', configuration: 'default')
    // aar dependency
    embed project(path: ':lib-aar', configuration: 'default')
    // aar dependency
    embed project(path: ':lib-aar2', configuration: 'default')
    // local full aar dependency, just build in flavor1
    flavor1Embed project(path: ':lib-aar-local', configuration: 'default')
    // local full aar dependency, just build in debug
    debugEmbed(name: 'lib-aar-local2', ext: 'aar')
    // remote jar dependency
    embed 'com.google.guava:guava:20.0'
    // remote aar dependency
    embed 'com.facebook.fresco:fresco:1.12.0'
    // don't want to embed in
    implementation('androidx.appcompat:appcompat:1.2.0')
}

Transitive

Local Dependency

If you want to include local transitive dependencies in final artifact, you must add embed for transitive dependencies in your main library.

For example, mainLib depend on subLib1, subLib1 depend on subLib2, If you want include all dependencies in the final artifact, you must add embed for subLib1 and subLib2 in mainLib build.gradle

Remote Dependency

If you want to inlcude all of the remote transitive dependencies which are in POM file, you need change the transitive value to true in your build.gradle, like this:

fataar {
    /**
     * If transitive is true, local jar module and remote library's dependencies will be embed. (local aar module does not support)
     * If transitive is false, just embed first level dependency
     * Default value is false
     * @since 1.3.0
     */
    transitive = true
}

If you change the transitive value to true,and want to ignore a dependency in its POM file, you can add exclude keywords, like this:

embed('com.facebook.fresco:fresco:1.11.0') {
    // exclude all dependencies
    transitive = false
    // exclude any group or module
    exclude(group:'com.facebook.soloader', module:'soloader')
}

More usage see example.

About AAR File

AAR is a file format for android library. The file itself is a zip file that containing useful stuff in android. See anatomy of an aar file here.

support list for now:

Gradle Version Support

VersionGradle PluginGradle
1.0.13.1.0 - 3.2.14.4 - 6.0
1.1.63.1.0 - 3.4.14.4 - 6.0
1.1.103.0.0 - 3.4.14.1 - 6.0
1.2.63.0.0 - 3.5.04.1 - 6.0
1.2.83.0.0 - 3.5.94.1 - 6.8
1.2.11 - 1.2.143.0.0 - 3.6.94.1 - 6.8
1.2.15 - 1.2.163.0.0 - 4.0.24.1 - 6.8
1.2.173.0.0 - 4.0.24.9 - 6.8
1.2.18+3.0.0 - 4.1.04.9 - 6.8
1.3.+3.0.0 - 4.1.04.9 - 6.8
1.3.4 - 1.3.53.0.0 - 4.1.04.9+
1.3.63.0.0 - 4.2.04.9+
1.3.83.0.0+4.9+

The following link which version of Gradle is required for each version of the Android Gradle plugin. For the best performance, you should use the latest possible version of both Gradle and the plugin.

Plugin version and Required Gradle version

Version Log

Known Defects or Issues

Thanks