deepmedia / Grease

Fat AARs for Android, to distribute multiple library modules in a single file with no dependencies, with relocation support.
Apache License 2.0
71 stars 1 forks source link
aar android android-lib android-library android-library-management android-studio fat fatjar fatjar-generator gradle gradle-plugin

Build Status Release Issues

Grease

A Gradle plugin for creating fat AARs, useful for distributing multiple modules in a single file. To install the plugin, apply it to your Android project:

// settings.gradle.kts
pluginManagement {
    repositories {
        mavenCentral()
    }
}

// build.gradle.kts
plugins {
    id("com.android.library")
    id("io.deepmedia.tools.grease") version "0.3.3"
}

Note: The minimum required version of Gradle is 8.3

Usage

Once applied, Grease will create Gradle configurations that you can use to select which of your dependencies should be bundled in the final fat AAR.

dependencies {
    // Api dependency. This will not be bundled.
    api("androidx.core:core:1.3.1")

    // Implementation dependency. This will not be bundled.
    implementation("androidx.core:core:1.3.1")

    // Grease dependency! This will be bundled into the final AAR.
    grease("androidx.core:core:1.3.1")

    // Build-type, product flavour and variant specific configurations.
    // Can be used to enable grease only on specific library variants.
    greaseRelease("androidx.core:core:1.3.1")
    greaseDebug("androidx.core:core:1.3.1")
    greaseBlueCircleDebug("androidx.core:core:1.3.1")
    greaseGreenTriangleRelease("androidx.core:core:1.3.1")
}

Note that we used androidx.core:core:1.3.1 as an example, but that is not recommended as it will likely cause compile issue on projects that consume the Grease AAR, if they already depend on the androidx.core:core:1.3.1 (as most project do).

If you don't control the projects that will consume the Grease AAR, you should only bundle in dependencies that you own, to be sure that they won't be present in the classpath of the consumer.

Transitivity

By default, declaring a specific grease dependency will not include transitive dependencies. To do so, you can use grease configurations ending in Tree:

dependencies {
    grease("my-package:artifact:1.0.0") // not transitive
    greaseTree("my-other-package:other-artifact:1.0.0") // transitive
}

Relocations

We support relocations through the popular Shadow plugin. Inside the grease extension, you can use: