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

Android中Fat AAR未包含子模块资源致运行崩溃求解决方案

Fat AAR未包含Feature模块资源导致运行时崩溃的排查与解决

可能原因

  1. 依赖配置不匹配:fat-aar-android默认仅处理implementation类型的依赖,若splash模块通过feature或其他特殊依赖方式引入,不会被纳入Fat AAR的打包范围。
  2. fat-aar配置遗漏:未在Library模块的fatLibrary配置块中明确声明需要合并的splash模块,导致工具忽略该模块的资源。
  3. 资源合并规则冲突:Library模块的资源配置中存在过滤/排除规则,或资源命名冲突(如重复资源名)导致splash的drawable被覆盖或丢弃。
  4. 构建缓存干扰:旧的R类缓存未更新,导致新加入的splash模块资源未被注入到最终的R类中。

解决方案

  • 修正依赖与fat-aar配置
    确保Library模块对splash的依赖使用implementation,并在fatLibrary块中显式包含该模块:

    // Library模块的build.gradle
    dependencies {
        implementation project(':splash')
    }
    
    fatLibrary {
        include project(':splash')
    }
    
  • 检查资源合并规则
    排查Library模块build.gradle中的资源配置,移除可能排除splash资源的规则:

    android {
        resources {
            // 确保没有类似这样的排除规则
            // exclude 'drawable/ic_app_splash.png'
        }
    }
    

    同时确认defaultConfig中未设置resourcePrefix导致资源命名冲突被覆盖。

  • 清理构建缓存并重新编译
    执行以下命令彻底清理缓存,避免旧R类干扰:

    ./gradlew clean :your-library-module-name:assembleRelease
    
  • 确认splash模块类型
    确保splash模块是Library类型(而非Application),修改其build.gradle的插件声明:

    // splash模块的build.gradle
    plugins {
        id 'com.android.library'
    }
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 11:30:55