如何在Android Studio中添加.aar文件到gradle.kts?

jdg4fx2g  于 2022-11-16  发布在  Android
关注(0)|答案(2)|浏览(514)

实现(fileTree(mapOf(“目录”到“库”,“包含”到列表(“*.jar”))))
实现(文件(“预算库NBB.aar”))

ztigrdn8

ztigrdn81#

建议的方法是使用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:
vsmadaxz

vsmadaxz2#

这非常简单,只需将*.aar包含在fileTree中即可
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar"))))
附言。当然,如果你仍然保持你的库在libs目录

相关问题