使用 Android Studio 3.XX,将本地 .AAR 文件添加到 Gradle 构建不起作用

Akk*_*kki 2 android gradle build.gradle android-gradle-plugin aar

使用 Android Studio 3.XX,将本地 .AAR 文件添加到 Android 项目不起作用(构建成功但运行时出现异常)

我尝试下面的方法(摘自参考来源:/sf/answers/1632847821//sf/answers/1742607121/等),但没有为我工作:

1. Import the local aar file:
   (I) File>New>New Module>Import the .AAR Package [On "Finish" click the .AAR gets included automatically into settings.gradle file as below:
       include ':app', ':myAAR'
   (II) Add AAR module dependency in app level build.grdle file as below:
       implementation project(":myAAR")

2. Using flatDir method:
   (I) keep aar file in libs folder
   (II) Add flatDir{dirs 'libs'} into the project level build.gradle file as below:
        allprojects {
            repositories {
                jcenter()
                flatDir {
                    dirs 'libs'
                }
            }
        } 
    (III) Add AAR dependency in app level build.gradle file as below:
          dependencies {
              implementation(name:'myAAR', ext: 'aar')
          }
Run Code Online (Sandbox Code Playgroud)

解决方法:需要将 AAR 模块导入的所有库都包含到应用程序级别的 gradle 中。似乎使用上述任何方法都不会传播来自 AAR 文件的导入。但是,我认为这不是正确的解决方案。在这里非常感谢任何帮助:)

Nic*_*hek 7

  1. 打开要添加 SDK 的 android 项目
  2. 点击文件 -> 新建模块 -> 导入 jar/arr 包
  3. File name: C://release.aa r

    Subproject name: my_subproject_name

  4. 单击完成
  5. 添加新的 SDK 模块作为对 app 模块的依赖:

app/build.gradle文件:

 dependencies {
        implementation fileTree(include: ['*.jar'], dir: 'libs')
        implementation project(':my_subproject_name')
}
Run Code Online (Sandbox Code Playgroud)

在外部库中的项目选项卡的结果中,您将看到您的库 在此处输入图片说明