Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add library module dependency to a Flutter Plugin's Android folder correctly? [closed]

I'm trying to write a Flutter plugin that relies on a third-party library on Android.

The dependency has a build.gradle file, I've got the source and I can build an aar file from the command line using gradle build.

I tried to add the dependency using Android Studio but it ended up in the my_plugin/example/android directory and no matter how many times did I try to move it to the plugin's my_plugin/android directory, I always failed.

The reason why this is an issue is that even though the example app can be built and run, I cannot use the plugin in other Flutter apps (which is the whole reason one would create a Flutter plugin).

How do I need to add a local library module (source code) or the aar (that I can build any time) to the Flutter plugin's Android implementation?

like image 292
Vince Varga Avatar asked Mar 05 '19 15:03

Vince Varga


People also ask

How do I add Flutter modules to my Android app?

Add to Android applications Auto-build and import the Flutter module by adding a Flutter SDK hook to your Gradle script. Build your Flutter module into a generic Android Archive (AAR) for integration into your own build system and for better Jetifier interoperability with AndroidX.

How do you add dependencies in Flutter?

I am new in flutter and I want to add Fast Android networking library to flutter dependencies and I don't know how to add, anyone, help me, please. You can go to the pubspec. yaml file and add dependencies ,under dependencies and then packages get will do the work. or you can run flutter pub get in the terminal.

How do I add a dependency to AAR?

Add your AAR or JAR as a dependency Navigate to File > Project Structure > Dependencies. In the Declared Dependencies tab, click and select Jar Dependency in the dropdown. In the Add Jar/Aar Dependency dialog, first enter the path to your .


Video Answer


1 Answers

well, you were halfway through the process...

  1. Go to File -> New module -> Select JAR/AAR, locate the JAR/AAR you want to add, decline creating a gradle wrapper and this will create a folder with your file and a build.gradle file. Copy the library folder name for usage in the next steps.
  2. Move the newly created folder to the android folder.
  3. Open settings.gradle in android folder and to the beginning of the file add this line:
    • include ':android/library_folder_name'
  4. Open build.gradle in android folder and in the dependencies block add this line:
    • implementation fileTree(dir: 'library_folder_name', include: ['*.aar', '*.jar'], exclude: [])
like image 105
rexxar Avatar answered Nov 01 '22 02:11

rexxar