11

I want to use Flutter to create an Android app which depends on a third-party SDK that wrapped in an aar file. So far, I have only found the article Accessing Platform and Third-Party Services in Flutter. It seems that I have to build the Flutter project with additional Java files using Android Studio. This is complicated and not what I want. Is there any way to directly load aar files or *.so files in Dart code? Something like how JNI works.

yushulx
  • 11,695
  • 8
  • 37
  • 64

2 Answers2

13

After learning the Flutter example - hello services, I have successfully built my Flutter project with aar file.

Basic Steps:

  1. Download the Flutter source code.
  2. Open flutter/examples/hello_services/android in Android Studio.
  3. Click File > New > New Module and choose Import .JAR/.AAR Package.
  4. Press F4 to open Project Structure, and then add the dependent module.
  5. Write Java code to invoke APIs that defined in aar file.
  6. Import flutter/examples/hello_services to Intellij IDEA.
  7. Build and run the Flutter app.

I've pushed the source code to GitHub.

yushulx
  • 11,695
  • 8
  • 37
  • 64
  • Unfortunately, flutter/examples/hello_services no longer exists. There is flutter/examples/platform_channel which may the way to do it now? – Ted Henry Aug 15 '19 at 23:16
  • @TedHenry. You dont need the example app. You can simply include the dependency by opening your "Android" folder inside the android studio and following the basic steps to include an aar file. And after that use method channels to invoke the native functions. – Jaswant Singh Aug 10 '20 at 11:52
0

If you want to add .aar file to your Flutter project and faced problem in Android Studio saying

" can't understand Gradle settings file, please add the path ':moduleName' manually"

enter image description here

this tutorial is how to add Android .aar module to your flutter project manually.

https://www.programmersought.com/article/84681807320/

abdullah
  • 157
  • 2
  • 8