With Android Studio 3.X.X, adding local .AAR file to Gradle build is not working [duplicate]

前提是你 提交于 2019-12-11 18:45:43

问题


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

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

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:


  1. Open the android project you want to add the SDK to
  2. Click file -> new module -> import jar/arr package
  3. File name: C://release.aar

    Subproject name : my_subproject_name

  4. Click Finish
  5. Add the new SDK module as dependency on app module:

app/build.gradle file:

 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



来源:https://stackoverflow.com/questions/54572613/with-android-studio-3-x-x-adding-local-aar-file-to-gradle-build-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!