【问题标题】:how to add .aar file to gradle.kts in android studio?如何在 android studio 中将 .aar 文件添加到 gradle.kts?
【发布时间】:2020-08-28 04:19:02
【问题描述】:

实现(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))

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

【问题讨论】:

  • 我在 libs 文件夹中有 .aar 文件,我想将当前在 libs 文件夹中的 .aar 导入到主项目中。请注意,我使用的是 Gradle.kts 文件系统。我只是尝试使用许多在线解决方案,但到目前为止似乎不是 wokring.if anybod 可以检查一下。下面是给定的问题

标签: android-studio kotlin gradle-kts


【解决方案1】:

推荐的方法是使用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: 

【讨论】:

    【解决方案2】:

    这很简单,只需将*.aar 包含在fileTree

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

    PS。当然,如果你仍然把你的图书馆保存在libs dir

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-07
      • 2022-10-19
      • 2017-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多