android studio: 子模块 Could not find aar 的问题
简单说下遇到的问题:
主模块app 依赖子模块 lib_ffmpeg, 子模块lib_ffmpeg 依赖一个aar: baidu-sdk.aar. 但是在编译时 gradle 始终提示:cound not find baidu-sdk.aar. 可我在lib_ffmepg的build.gradle文件里已添加:
implementation(name: 'baidu-sdk', ext: 'aar')
解决办法
1. 找到项目级别的build.gradle, 添加红字部分:
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { maven { url 'https://maven.aliyun.com/repository/public' } maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'https://maven.aliyun.com/repository/central' } maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } } dependencies { classpath 'com.android.tools.build:gradle:7.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { maven { url 'https://maven.aliyun.com/repository/public' } maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'https://maven.aliyun.com/repository/central' } maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } flatDir { dirs project(':lib_ffmpeg').file('libs') // 我的aar文件已放置到 lib_ffmpeg 模块的libs目录下 } } } task clean(type: Delete) { delete rootProject.buildDir }
2. 找到 lib_ffmepg的build.gradle文件,删除(如果之前已添加):
implementation(name: 'baidu-sdk', ext: 'aar')
因为上述gradle文件里已指定:
implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'], exclude: [])
完成上述两步后,重新sync下项目就好了。第二步如果不做的话可能会报 Duplicate class 的错误。
参考链接:
1. 疑难杂症(一)集成优酷sdk[aar] library Module 依赖,找不到aar[Could not find :YoukuPlayerOpenSDK-release:.]
2. Android Studio多Module使用 aar 依赖包 丢包解决