使用Android Studio 3.X.X,无法将本地.AAR文件添加到Gradle构建中

时间:2019-02-07 11:44:04

标签: android gradle android-gradle build.gradle aar

在Android Studio 3.X.X中,无法将本地.AAR文件添加到Android项目中(构建成功,但获取了运行时异常)

我尝试了以下方法(参考来源:https://stackoverflow.com/a/23326397/5685911https://stackoverflow.com/a/24894387/5685911等),但没有一个对我有用:

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')
          }

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

1 个答案:

答案 0 :(得分:0)

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

    Subproject name my_subproject_name

  4. 点击完成
  5. 添加新的SDK模块作为对应用程序模块的依赖项:

app / build.gradle 文件:

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

在外部库的“项目”选项卡中,您将看到您的库 enter image description here