Q:

Build AAR with dependencies

I want to build .AAR with dependencies inside. I was looking for a lot but nothing works. Topics are so old. I realized that resultant .AAR should have classes.jar inside and there are directories with .class files. But I don't know how to automatize this process in gradle.

A:

Android tooling doesn't support it. There's an issue open requesting Google to implement it (feel free to star it to show your support and to help Google to prioritize it).
In the meantime, there are two plugins to try to fix or workaround this lack of support, with limited support of different functionalities:

https://github.com/adwiv/android-fat-aar Old, no longer supported.
https://github.com/Mobbeel/fataar-gradle-plugin Still active, but lagging behind AGP versions (currently working on supporting 3.2 and 3.3... while we're already at 3.4 stable)

So, as you can see the future doesn't look bright.
See also this article for more information.

A:

We manage to do this using this Mobbeel fat AAR Gradle plugin:
https://github.com/Mobbeel/fataar-gradle-plugin
    buildscript {
        repositories {
            //...
            maven {
                url 'https://plugins.gradle.org/m2/'
            }
        }
    }

    //...

    dependencies {
        classpath 'gradle.plugin.com.mobbeel.plugin:mobbeel-fataar:1.2.0'
    }

Mark dependencies with api instead of implementation
    apply plugin: 'com.mobbeel.plugin'

    dependencies {
        api 'org.greenrobot:eventbus:3.0.0'
        //...
    }

    fatAARConfig {
        includeAllInnerDependencies false
    }

This article was helpful: http://wittchen.io/2018/10/02/creating-fat-aar/

