You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

含AAR依赖的模块导出AAR时内部依赖无法解析问题咨询

AAR嵌套依赖问题的解决方案

Great question! Let's break this down clearly.

First off: AAR files do NOT support directly nesting other AARs as internal dependencies by default. Here's why: An AAR is essentially an archive that contains your module's compiled code, resources, and a metadata file (like pom.xml or Gradle module metadata) that lists its dependencies. It doesn't actually package the dependent AARs into itself—instead, it expects the consuming project to resolve those dependencies from a repository.

That's why when you export your module as an AAR, the consuming project can't find the internal AAR dependencies: those dependencies aren't present in your exported AAR, and there's no way for the consumer's build system to know where to get them unless properly configured.

Here are the most common and practical solutions to fix this:

  • Publish all dependent AARs to a Maven repository (local or remote)
    This is the standard, recommended approach. Upload both your module's AAR and all its dependent AARs to a Maven repo (you can use a local repo for testing, or a remote one like Maven Central, JFrog Artifactory, etc.). Then, in your module's build configuration, use implementation to reference those dependent AARs from the repo. When you export your module's AAR, its metadata will include the dependency references, and the consuming project just needs to add the same repo to its build settings to resolve all dependencies automatically.

  • Use the fat-aar Gradle plugin to bundle dependencies into your AAR
    If you need a single self-contained AAR that includes all dependent code and resources, you can use third-party plugins like fat-aar (or fat-aar-android). This plugin lets you replace implementation with embed for the AARs you want to bundle. It will merge the classes, resources, JNI libraries, and other assets from the dependent AARs into your final AAR.
    Example configuration snippet in your module's build.gradle (Groovy):

    plugins {
        id 'com.android.library'
        id 'com.kezong.fat-aar' version '1.3.8'
    }
    
    dependencies {
        // Embed the dependent AAR instead of using implementation
        embed files('libs/dependency.aar')
    }
    

    Note: Be careful with duplicate dependencies or resource conflicts when using this approach, and make sure you have the legal right to bundle third-party AARs into your own.

  • Manually merge dependent AAR contents into your module (not recommended)
    As a last resort, you can extract the contents of each dependent AAR (unzip it) and merge its classes.jar, resource files, JNI folders, etc., into your module's corresponding directories. This is error-prone, hard to maintain, and likely to cause conflicts, so only use this if other options aren't feasible.

内容的提问来源于stack exchange,提问作者Sumit Sahoo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:17:07