'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:
Then make a new directory in project level named libs
Now right click the libs and select Reveal in finder and then paste here your .aar file.
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:
- 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'
- Paste the MyLib.aar file in that directory.
- 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.
In the project level build.gradle file, change the line
include ':app'
toinclude ':app', ':MyLib'
In the app module build.gradle, add the following line in the depedencies section
implementation project(":MyLib")
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:
Copy .aar file into the libs folder of the app
File -> Project Structure... -> Dependencies
- Click on "+" icon and select JR/AAR Dependency and select app module
- Add .aar file path in step 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 |