androidflutterpluginsnativeaar

Importing aar file in Flutter Plugin


Importing aar file directly in flutter project is easy and straight-forward but in flutter plugin its not. When importing aar file in flutter plugin I get the following error : -

Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR. Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error).

This issue can be solved using the following command : -

compileOnly fileTree(dir: 'libs', include: ['*.aar'])

but this line only complies the file but when using it in a project it file wont get imported.

How can I import aar file in flutter plugin ?

I have scrutinized each and every solution but nothing works. Solution of following links did not work : -

How to Import AAR file in the flutter plugin?

How to use local aar inside flutter plugin?

How to build Flutter project with Android aar file?

How to build Flutter project with Android aar file?


Solution

  • enter image description here

    enter image description here

    rootProject.allprojects {
        repositories {
            google()
            mavenCentral()
            flatDir {
                dirs project(':YOUR_FLUTTER_PLUGIN_NAME').file("libs")
            }
        }
    }
    

    As shown above, you need to add rootProject.allprojects, and in
    dirs project(':YOUR_PLUGIN_NAME').file("libs"), otherwise your project won't be able to find resources under libs when importing the plugin. Also, in dependencies, you need to add

    api(name: 'YOUR_AAR_NAME', ext: 'aar')
    

    otherwise it won't be able to find the dependencies of the plugin