5

实现(fileTree(mapOf(“dir”到“libs”,“include”到listOf(“*.jar”))))

实施(文件(“BudgetLibraryNBB.aar”))

4

2 回答 2

5

推荐的方法是使用File-> New-> New Module->导入它Import .JAR/.AAR Package,然后在库模块build.gradle.kts文件中引用它:

implementation(project(":BudgetLibraryNBB"))

如果你把它放到 libs 目录中:

implementation(files("./libs/BudgetLibraryNBB.aar"))

或者

implementation(files("$projectDir/libs/BudgetLibraryNBB.aar"))

当您执行 bundleAar 任务时,您将遇到以下错误:

Execution failed for task ':common:bundleDebugAar'.
> Direct local .aar file dependencies are not supported when building an AAR. The 
resulting AAR would be broken because the classes and Android resources from any 
local .aar file dependencies would not be packaged in the resulting AAR. Previous 
versions of the Android Gradle Plugin produce broken AARs in this case too 
(despite not throwing this error). The following direct local .aar file 
dependencies of the :common project caused this error: 

于 2020-07-25T15:32:45.090 回答
4

这真的很简单,只需包含*.aarfileTree

implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar"))))

PS。当然,如果您仍然将库保存在libs目录中

于 2020-09-21T08:04:39.117 回答