1、项目根目录新建目录libs,将aar放入,目录结构图如下:

/root-project
  ├── libs/
  │   └── your-library.aar
  ├── settings.gradle.kts
  └── app/
       └── build.gradle.kts

2、修改 settings.gradle.kts

添加 dependencyResolutionManagement 配置,声明仓库路径:

// settings.gradle.kts
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        // 添加本地 libs 目录作为仓库
        flatDir {
            dirs("libs") // 指向根目录的 libs 文件夹
        }
    }
}

3、在模块中引用 AAR

在 app/build.gradle.kts 中添加依赖:

dependencies {
    // 直接拼接字符串
    implementation(":your-library@aar")
}

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐