使用Android Studio 3.X.X,无法将本地.AAR文件添加到Gradle构建中 [英] With Android Studio 3.X.X, adding local .AAR file to Gradle build is not working

查看:751
本文介绍了使用Android Studio 3.X.X,无法将本地.AAR文件添加到Gradle构建中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

With Android Studio 3.X.X, adding local .AAR file to Android project is not working (Build is success but getting runtime exceptions)

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

I tried below methods (Taken reference From: https://stackoverflow.com/a/23326397/5685911, https://stackoverflow.com/a/24894387/5685911, etc.), but none worked for me:

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文件导入的内容. 但是,我认为这不是正确的解决方案.非常感谢您的任何帮助:)

Worked around: Need to include all the library imported by the AAR module into the app level gradle. It seems imports from the AAR file are not propagated using any of the above method. BUT, I think it is not the proper solution. Any help would be appreciated here with a big THANKS :)

推荐答案

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

Subproject name: my_subproject_name

app/build.gradle 文件:

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

在外部库的项目"选项卡中,您将看到您的库

In result at Project tab in External Libraries you will see your lib

这篇关于使用Android Studio 3.X.X,无法将本地.AAR文件添加到Gradle构建中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆