simolus3 / drift

Drift is an easy to use, reactive, typesafe persistence library for Dart & Flutter.
https://drift.simonbinder.eu/
MIT License
2.55k stars 365 forks source link

Incomplete bundle release when using drift #2537

Closed ltOgt closed 1 year ago

ltOgt commented 1 year ago

First of all, thanks for building and maintaining this awesome package!


Google Play Consoles Pre-Launch report gave me the following issue:

java.lang.RuntimeException: Unable to start activity
...
java.lang.UnsatisfiedLinkError
...
/lib/x86, /system/lib]]] couldn't find "libflutter.so"

After some digging i found that bundling my project (flutter build appbundle) included an incomplete x86 directory.

Whereas no such directory was included at all when bundling a project without drift.

I opened the resulting app-release.abb with Archive Utility, and under .../build/app/outputs/bundle/release/app-release/base/lib/x86/ i get


This may be a flutter issue instead, not sure.

ltOgt commented 1 year ago

Manually including the following in android/app/build.gradle seems to fix this:

...
android {
   ...
   buildTypes {
       release {
           ...
           ndk {
               // explicit list of supported targets
               // implicit excluded 'x86'
               abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86_64'
           }
       }
   }
}

But would be nice if this was not necessary, since it works fine out of the box when not using drift

simolus3 commented 1 year ago

First of all, thanks for building and maintaining this awesome package!

Thanks!

As you've found out, explicitly adding an abiFilters entry to the Gradle buildscript fixes the problem. I agree that it would be very nice if this wasn't necessary, and with a future Flutter/Dart release with this feature we won't need this.

At the moment, the only reliable way to bundle native code in a Flutter plugin (like sqlite3_flutter_libs) in this case is to publish a precompiled library to a repository. That library needs to support all architectures an app might want to support, which includes x86. Some Flutter users are running production apps on x86, but this is a very weird setup because it's not supported by Dart's AOT compiler so they essentially run a JIT build without assertions. We include x86 to support these users (and since it might be useful for those testing their apps on an emulator).

However, it seems like there is no way for that library to say "just include the platforms that the main app supports" without you adding that abiFilters call. This is documented in the readme here, but since most users probably don't care about that package and just blindly add it because I recommend it in drift's documentation, I'm being a bit irresponsible here. I will update the documentation to mention this limitation but without native assets, I think that's all I can do.