Android中Fat AAR未包含子模块资源致运行崩溃求解决方案
Fat AAR未包含Feature模块资源导致运行时崩溃的排查与解决
可能原因
- 依赖配置不匹配:fat-aar-android默认仅处理
implementation类型的依赖,若splash模块通过feature或其他特殊依赖方式引入,不会被纳入Fat AAR的打包范围。 - fat-aar配置遗漏:未在Library模块的
fatLibrary配置块中明确声明需要合并的splash模块,导致工具忽略该模块的资源。 - 资源合并规则冲突:Library模块的资源配置中存在过滤/排除规则,或资源命名冲突(如重复资源名)导致splash的drawable被覆盖或丢弃。
- 构建缓存干扰:旧的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
相关产品推荐
相关产品推荐

