如何在android studio中将.aar文件添加到gradle.kts?

时间:2020-05-12 10:49:12

标签: android-studio kotlin gradle-kts

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

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

2 个答案:

答案 0 :(得分:1)

recommond方法是使用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: 

答案 1 :(得分:0)

这真的很简单,只需在*.aar中包含fileTree

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

PS。当然,如果您仍将图书馆保留在libs目录中