如何将.AAR作为一个新模块包含在android项目中?

如何将.AAR作为一个新模块包含在android项目中?,android,android-studio,sdk,aar,Android,Android Studio,Sdk,Aar,我试图将.AAR文件作为一个模块包含在我的项目中。因此,为了使我的项目代码保持模块化,我尝试了针对堆栈溢出给出的解决方案,但没有任何效果。最后,我找到了一种方法,以最佳方式添加到项目中 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

我试图将.AAR文件作为一个模块包含在我的项目中。因此,为了使我的项目代码保持模块化,我尝试了针对堆栈溢出给出的解决方案,但没有任何效果。最后,我找到了一种方法,以最佳方式添加到项目中

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文件夹中

在项目级别,添加以下代码

allprojects {
    repositories {
        google()
        jcenter()

        ***flatDir{
            dirs 'libs'
        }***

        maven { url 'https://www.jitpack.io' }
        maven {url 'https://developer.huawei.com/repo/'}
    }
}
dependencies {
    **implementation fileTree(dir: 'libs', include: ['*.aar'])**
}
同步你的Gradle文件

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

allprojects {
    repositories {
        google()
        jcenter()

        ***flatDir{
            dirs 'libs'
        }***

        maven { url 'https://www.jitpack.io' }
        maven {url 'https://developer.huawei.com/repo/'}
    }
}
dependencies {
    **implementation fileTree(dir: 'libs', include: ['*.aar'])**
}
在项目级渐变中添加以下代码

dependencies {
        implementation project(': your module name')
    }
同步你的Gradle文件

就这样。 注意:这是在项目中导入.AAR文件的最佳方式