使用依赖项构建 AAR

Build AAR with dependencies

我想构建带有依赖项的 .AAR。我一直在寻找很多,但没有任何效果。话题太老了我意识到生成的 .AAR 内部应该有 classes.jar 并且有包含 .class 文件的目录。但是我不知道如何在 gradle.

中使这个过程自动化

Android 工具不支持它。有一个 issue open 请求 Google 实施它(随时给它加注星标以表示您的支持并帮助 Google 确定它的优先级)。

同时,有两个插件试图修复或解决这种缺乏支持的问题,但对不同功能的支持有限:

所以,如你所见,未来并不光明。

另请参阅 this article 了解更多信息。

我们设法使用这个 Mobbeel fat AAR Gradle 插件来做到这一点: 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'
    }

api而不是implementation

标记依赖关系
    apply plugin: 'com.mobbeel.plugin'

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

    fatAARConfig {
        includeAllInnerDependencies false
    }

这篇文章很有帮助:http://wittchen.io/2018/10/02/creating-fat-aar/