'How to import .AAR module on Android Studio 4.2

Previously I used File > New > New Module > Import .JAR/.AAR Package

but the option to Import .JAR/.AAR Package from the New Module wizard has been removed on Android Studio 4.2 and following the document which suggests using the Project Structure Dialog reveals no clear answer for importing .AAR module and seems to be outdated

I tried adding the module as a dependency in the project Structure but it did not work



Solution 1:[1]

From Android Studio package manager select project:

enter image description here

Then make a new directory in project level named libs

enter image description here

enter image description here

Now right click the libs and select Reveal in finder and then paste here your .aar file.

enter image description here enter image description here

Now in Build.gradle(Module) add the following implementation.

implementation files('../libs/testaarfile.aar') 

and snyc your project.

Solution 2:[2]

If you want to add your .aar file as a different module and not as a dependency to the main 'app' module in Android Studio 4.2, You can try the following:

  1. Create a new folder in the same directory where your 'app' module is located and name it same as your .aar for example 'MyLib' for 'MyLib.aar'
  2. Paste the MyLib.aar file in that directory.
  3. Open notepad and type the following:

configurations.maybeCreate("default")

artifacts.add("default", file('MyLib.aar'))

and save the file as build.gradle in the 'MyLib' folder.

  1. In the project level build.gradle file, change the line include ':app' to include ':app', ':MyLib'

  2. In the app module build.gradle, add the following line in the depedencies section

    implementation project(":MyLib")

  3. Sync the project and do a clean rebuild

Solution 3:[3]

For Android Studio Bumblebee | 2021.1.1 Patch 3

I have followed steps suggested by the Android developer site:

  1. Copy .aar file into the libs folder of the app

  2. File -> Project Structure... -> Dependencies

enter image description here

  1. Click on "+" icon and select JR/AAR Dependency and select app module

enter image description here

  1. Add .aar file path in step 1.

enter image description here

  1. Check your app’s build.gradle file to confirm a declaration.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RestingRobot
Solution 2 Sourish Ghosh
Solution 3 SANAT