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

本文为作者原创,允许转载,不过请在文章开头明显处注明链接和出处!!! 谢谢配合~
作者:stars-one
链接:https://www.cnblogs.com/stars-one/p/16892387.html

本篇大约有1274个字,阅读预计需要1.59分钟


原文: 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 @   Stars-one  阅读(2326)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端
点击右上角即可分享
微信分享提示