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')

參考

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章