Search code examples
android-libraryflutter-plugin

How to include an Android library inside Flutter plugin


I have custom native iOS and Android libraries. Now I need to create a Flutter plugin that includes these libraries for developing Flutter apps that use these libraries. I already set up the iOS library in the Flutter plugin project. But I am having difficulty including the Android library. The Android library is an .aar file. I searched online, but found limited information on this. None of the solutions work. Basically the issue is this: Direct local .aar file dependencies are not supported when building an AAR.

Here is one discussion on this. But I don't find any that works in my case. stackoverflow.com/questions/60878599/error-building-android-library-direct-local-aar-file-dependencies-are-not-supp

Any help is greatly appreciated.


Solution

  • Since I can also use a .jar file, I used the solution from this link Calling native libraries in Flutter using Platform Channels.

    To summarize it: First put the .jar file in a location, open the plugin project in Android Studio. Then from File menu, open Project Structure, select Modules, and then click + to add the .jar file. After that, from the plugin project's android folder, open build.gradle, add implementation file('path/to/jar'). in dependencies section.