2

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 :)

Molly
  • 1,887
  • 3
  • 17
  • 34
Akki
  • 775
  • 8
  • 19

1 Answers1

7
  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 enter image description here

NickUnuchek
  • 11,794
  • 12
  • 98
  • 138