This fork adds support for AGP 8.0+
The solution of merging aar works with AGP 8.5 and Gradle 8.7
buildscript {
repositories {
...
maven { setUrl("https://jitpack.io") }
}
dependencies {
classpath("com.github.empatica.fat-aar-android:com.empatica.fat-aar.gradle.plugin:<version>")
}
}
Add the plugin to the build.gradle
of your main android library:
plugins {
id("com.android.library")
...
id("com.empatica.fat-aar")
}
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')
}
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
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')
}
It may be possible that if you transitively embed a dependency in you project, you end up embedding also dependencies that are shared among other embedded modules.
For example, working with dependencies that use androidx.*
artifacts will result in embedding androidx.*
artifacts multiple times. This will eventually break the build due to artifacts duplication.
If you want to include only artifacts of a particular group, use this directive in the fataar
configuration block:
fataar {
// transitively embed all the dependencies
transitive = true
// transitively include only the dependencies with group `com.example` and `com.mycompany`
includedDependenciesGroups = setOf("com.example", "com.mycompany")
}
More usage see example.
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:
- Flavors
- AndroidManifest merge
- Classes merge
- Jar merge
- Res merge
- Assets merge
- Jni libs merge
- R.txt merge
- R.class merge
- DataBinding merge
- Proguard merge
- Kotlin module merge
Version | Android Gradle Plugin | Gradle |
---|---|---|
1.4.1 | 8.5 | 8.7 |
1.4.0 | 8.3 | 8.6 |
1.3.8 | 3.0.0+ | 4.9+ |
1.3.6 | 3.0.0 - 4.2.0 | 4.9+ |
1.3.4 - 1.3.5 | 3.0.0 - 4.1.0 | 4.9+ |
1.3.+ | 3.0.0 - 4.1.0 | 4.9 - 6.8 |
1.2.18+ | 3.0.0 - 4.1.0 | 4.9 - 6.8 |
1.2.17 | 3.0.0 - 4.0.2 | 4.9 - 6.8 |
1.2.15 - 1.2.16 | 3.0.0 - 4.0.2 | 4.1 - 6.8 |
1.2.11 - 1.2.14 | 3.0.0 - 3.6.9 | 4.1 - 6.8 |
1.2.8 | 3.0.0 - 3.5.9 | 4.1 - 6.8 |
1.2.6 | 3.0.0 - 3.5.0 | 4.1 - 6.0 |
1.1.10 | 3.0.0 - 3.4.1 | 4.1 - 6.0 |
1.1.6 | 3.1.0 - 3.4.1 | 4.4 - 6.0 |
1.0.1 | 3.1.0 - 3.2.1 | 4.4 - 6.0 |
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
- 2.0.0
- Empatica fork and support for transitive inclusion of specified dependencies groups
- 1.4.1
- Support AGP 8.5
- 1.4.0
- Support AGP 8.3
- 1.3.8
- Fix the issue that plugin cannot be used in jdk 1.8 #371
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- Support Gradle 6.8 #274
- 1.3.3
- Fix bug that "Can not find task bundleDebugAar". #84
- Fix bug that crash when module can not resolve.
- Throw a runtime exception when manifest merge fail.
- 1.3.1
- Implement bytecode patching to process R class
- Support merge consumerProguardFiles
- Support merge *.kotlin_module, support kotlin top-level
- Support flavor missingDimensionStrategy
- Fix build error when flavor artifact renamed
- Fix Jar merge error when use AGP 3.0 - 3.1
- Fix AGP version not found in some cases
- 1.2.20
- Fix error that getName() in a null object. #214
- Rename r-classes.jar with applicationId.
- 1.2.19
- 1.2.18
- Adapt gradle plugin 4.1.0 #201
- 1.2.17
- 1.2.16
- 1.2.15
- 1.2.12
- 1.2.11
- Fix build variants error in gradle plugin 3.6.+ #126
- Fix bug that remote recources symbol can not found in R.class when build with gradle plugin 3.6.0+
- 1.2.9
- adapt gradle plugin 3.6.1 #120
- 1.2.8
- adapt gradle 6.0.0+ #97
- 1.2.7
- 1.2.6
- 1.2.5
- Fix task name repeat error #48
- If minifyEnabled, jar files would build into classes.jar
- 1.2.4
- Fix jni and assets can't embed in windows platform #37
- 1.2.3
- 1.1.11
- 1.1.10
- 1.1.8
- 1.1.7
- Support embed R file when upload maven #7
- 1.1.6
- 1.0.3
- Fix assets merge
- 1.0.1
- Support gradle plugin 3.1.0 - 3.2.1
- Support R class file merge
-
Application cannot directly rely on embedded project: application cannot directly rely on your embedded project. It must rely on the AAR file compiled by your embedded project
- For debugging convenience, you can use
embed
in the main library project when you choose to package aar. When you need to run the app directly, you can useimplementation
orapi
- For debugging convenience, you can use
-
Res merge conflicts. If the library res folder and embedded dependencies res have the same res Id(mostly
string/app_name
). A duplicate resources build exception will be thrown. To avoid res conflicts:- consider using a prefix to each res Id, both in library res and aar dependencies if possible.
- Adding
android.disableResourceValidation=true
togradle.properties
can do a trick to skip the exception.
-
Proguard
- If
minifyEnabled
is set to true, classes not referenced in the project will be filtered according to Proguard rules during compile, resulting in ClassNotFound during app compile. Most AAR is SDK that provide interfaces. It is recommended that you carefully comb Proguard files and add keep rules.
- If