android studio: Could not find aar 的问题

简单说下遇到的问题

主模块app 依赖 lib下的.aar包,但是在编译时 gradle 始终提示:cound not find xxxxx.aar. 可我在app的build.gradle文件里已添加:

implementation(name: 'xxxxx', ext: 'aar')

解决办法

1. 找到项目级别的build.gradle, 添加红字部分:

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文件已放置到 app模块的libs目录下
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

2. 找到 app的build.gradle文件,删除(如果之前已添加):

implementation(name: 'xxxx', ext: 'aar')

注意:因为上述gradle文件里已指定(检查下build.gradle有没有加下面这句引入):

implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'], exclude: [])

或者是,引入如下这句:

api(name: '你的aap的包名', ext: 'aar')

以上两句配置2选1

完成上述两步后,重新sync下项目就好了。第二步如果不做的话可能会报 Duplicate class 的错误

最后要确认下是否引入成功

android studio: Could not find aar 的问题_第1张图片

1、将工程显示目录切换到Project

2、点击External Libraries,在其中找一下想引入的依赖包,如果没有说明引入失败,需要检查配置是否有问题。

你可能感兴趣的:(android,studio,android,gradle)