How to Import AAR file in the flutter plugin?

Viewed 32

I am working in a flutter plugin and want to import an .aar project in android part of the plugin. I have tried opening the android project and importing the .aar project by importing the module, including it in setting.gradle and adding it in dependency of build.grade (like any other native android project). However, when I run the flutter project, the .aar project is not found.

The error I get is

A problem occurred evaluating project ':flutter_plugin_andriod'

Project with path ':commonlib' could not be found in project ':flutter_plugin_andriod'.

enter image description here

Anybody with the fix ?

2 Answers

I finally found the answer.

  • create a lib folder in directory where the build.gradle is and place your aar file in the folder.
  • Then add flatDir { dirs 'lib'} in your rootProject.allprojects
  • Then add dependency in the build. file in the dependencies section as:
    api(name: 'your_aar_file_name', ext: 'aar')

    Note: Make sure to add all the dependencies included in gradle.build file (if your aar file depends on any gradle.build file of its own) in the dependencies section of your application build.gradle file . This was the main issue in my case.

Put your .aar in Android/app/libs In Android/app/build.gradle you import the aar :

dependencies {
   implementation fileTree(include: ['*.jar'], dir: 'libs')
   implementation files('libs/myaarlibr.aar')
}

After this your .aar is ready for use

Related