【问题标题】:How to include .AAR as a new module in android project? [duplicate]如何将 .AAR 作为新模块包含在 android 项目中? [复制]
【发布时间】:2021-08-12 22:31:55
【问题描述】:

我试图将 .AAR 文件作为模块包含在我的项目中。因此,我可以将我的项目代码保持为模块化,我尝试了在堆栈溢出时给出的解决方案,但没有按我要求的方式工作。最后我找到了一种以最好的方式添加到项目中的方法。

【问题讨论】:

    标签: android android-studio sdk aar


    【解决方案1】:
    This is tested and working fine in my project. Android studio ver 4.4.
    
    Click File -> New Module -> Select Android Library.
    Added Module name -(Of your choice)
    Package name - (Of your choice)
    Language - Java/Kotlin
    Bytecode Level -8 
    Min SDK support - (Of your choice)
    Click **Finish**.
    

    将在您的项目中创建一个模块。该模块将有一个 libs 文件夹。将 .AAR 文件粘贴到 lib 文件夹中。

    在项目级别 gradle 添加以下代码。

    allprojects {
        repositories {
            google()
            jcenter()
    
            ***flatDir{
                dirs 'libs'
            }***
    
            maven { url 'https://www.jitpack.io' }
        }
    }
    

    同步您的 Gradle 文件。

    现在,转到您的模块级 gradle 文件添加以下代码。

    dependencies {
        **implementation fileTree(dir: 'libs', include: ['*.aar'])**
    }
    

    在项目级 gradle 中添加以下代码。

    dependencies {
            implementation project(': your module name')
        }
    

    同步您的 Gradle 文件。

    就是这样。 注意:最好在项目中导入.AAR文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 2015-11-11
      • 2021-06-10
      • 1970-01-01
      • 2016-10-22
      • 1970-01-01
      相关资源
      最近更新 更多