How to import .AAR module on Android Studio 4.2
Asked Answered
H

4

36

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

Hearty answered 27/5, 2021 at 14:28 Comment(0)
G
43

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.

Goliard answered 27/5, 2021 at 14:44 Comment(5)
Yes I use this method for adding aar filesMattox
This method usually doesn't work on Flutter plugins, for example. The old way, creating a project works. But could not find it on the new Android Studio 4.2 either.Pannikin
Does not work on latest Android Studio as they have changed the layout of the package manager.Rotate
Working perfectly for my Flutter pluginJandel
2023: Looks like it is ('libs/testaarfile.aar')Epitomize
W
13

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 settings.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

Wally answered 25/3, 2022 at 8:26 Comment(1)
I wish I could offer 1000 upvotes for this answer. In the desperate throes of retrofitting an ancient application, I found myself needing to follow instructions from a repository several years old that required the Import .JAR/.AAR Package functionality. This answer worked perfectly.Merrymaker
P
9

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.
Penelopa answered 9/5, 2022 at 14:49 Comment(0)
B
0

Simply add the following line in app/build.gradle

implementation(files("libs/library_name.aar"))

This works well with latest versions of Android

Bristletail answered 4/4 at 8:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.