Android 模块导入AAR时报错

Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR. Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error). The following direct local .aar file dependencies of the :XXX project caused this error:

构建aar时不支持AAR文件依赖关系

以前版本的Android Gradle插件在这种情况下也会产生错误的AAR(尽管没有抛出这个错误)

解决方案:implementation 改为 compileOnly

Groovy 复制代码
libs下aar文件
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])

把他改为
compileOnly fileTree(dir: 'libs', include: ['*.jar', '*.aar'])

implementation 依赖项在编译时和运行时都可见,并将包含在最终的构建输出中。这是最常用的依赖配置,用于指定项目在编译和运行时都需要的依赖项。
compileOnly 依赖项仅在编译时可见,而在运行时不包含在最终的构建输出中。这意味着虽然在编译代码时可以使用这些依赖项,但它们不会被打包到最终的 JAR 或 APK 文件中。通常,compileOnly 用于指定在编译时需要,但在运行时由其他模块或系统提供的依赖项。

他仅仅只能消除警告

要在主项目导入

相关推荐
符哥20081 小时前
新能源智能充电桩与 Android/iOS App 蓝牙通信协议
android·ios
JMchen1232 小时前
自定义View性能优化:从60fps到120fps的进阶之路
android·经验分享·性能优化·kotlin·自定义view
vistaup2 小时前
DevEco Studio 鸿蒙 HAR本地引入相互依赖问题解决
android·华为·harmonyos
常利兵2 小时前
Android 开发秘籍:用Tint为Icon动态变色
android
奔跑吧 android3 小时前
【车载audio】【CarAudioService 05】【车载 Android 系统调试深度指南:解析 dumpsys car_service】
android·audio·audioflinger·aosp15·车载音频·车载audio·car_service
shuangrenlong3 小时前
androidstudio gradle文件报红
android
Digitally3 小时前
如何通过蓝牙将 iPhone 上的照片传输到 Android
android·ios·iphone
常利兵3 小时前
Android Intent.setAction失效报错排查与修复全方案
android
低调小一3 小时前
RecyclerView 缓存与复用机制:从一次滑动讲明白(2026 版)
android·recyclerview
耶叶3 小时前
kotlin的修饰符
android·开发语言·kotlin