Android 多module情况下module依赖aar问题处理

原文: Android 多module情况下module依赖aar问题处理 - Stars-One的杂货小窝

问题描述

负责一个大项目Android工程项目,新增了一个module,而此module由于sdk的关系,需要引入SDK的aar文件

在Module的build.gradle文件里引入:

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

准备运行项目的时候报错:

Could not determine the dependencies of task ':app:preDebugBuild'.
> Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
   > Could not find :alipaysdk-15.8.03.210428205839:.
     Required by:
         project :app > project :lib_share

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

解决方法

方法1

在所有需要依赖此module的build.gradle 文件中添加此配置:

repositories {
    flatDir {
        dirs '../lib_share/libs'
    }
}

比如,我是在app的module去引用了我的这个Module,应该在app里的build.gradle文件中写上上述代码,如下图所示:

方法2

如果有很多模块都依赖了这个模块,可以在全局的build.gradle(根目录)配置

repositories {
    flatDir {
        dirs project(":ocr").file("libs")
    }
}

方法3

更改一下依赖方式,如下所示:

implementation files('libs/ocrsdk.aar')

参考

posted @ 2022-11-15 14:41  Stars-one  阅读(1895)  评论(0编辑  收藏  举报