1

I'm creating a Flutter application that includes multiple 3rd party libraries. On the Android side these libraries are .so files and .jar files.

The libraries are included and work great in debug builds, but in release builds the .jar files are not included in the apk/appbundle.

I'm using this line to import the .jar files in android/app/build.gradle:

  implementation fileTree(dir: 'libs', include: ['*.jar'])

The application crashes on launch from the release build as the libraries are not present and I seem to have exhausted my Google-fu in this matter. I have everything working like this and because of time pressure on the project I'm rather hesitant to start re-creating this as a Flutter plugin.

Any suggestions on what I should do to make release builds include the libraries?

Covalence
  • 130
  • 7
  • Does this answer your question? [Calling native libraries in Flutter using Platform Channels](https://stackoverflow.com/questions/50020347/calling-native-libraries-in-flutter-using-platform-channels) – Rajen Raiyarela Jun 22 '20 at 05:21
  • @RajenRaiyarela I read through that before posting but being under time pressure and having everything otherwise working I'm hoping to find a solution that doesn't involve creating a plugin project first. – Covalence Jun 23 '20 at 04:45

1 Answers1

0

You can import jar libraries to your Flutter app using Platform Channels. The jar library can be called using platform-specific code (i.e. Kotlin/Java). Jars can also be imported using Kotlin because of its interoperability.

The jar library won't be included in the APK per se, but the code that you've used from the jar will become part of the Android code as explained in this post.

Omatt
  • 8,564
  • 2
  • 42
  • 144