nmfisher / thermion

3D rendering toolkit for Dart and/or Flutter
https://thermion.dev
Apache License 2.0
125 stars 10 forks source link

Investigate how to use shrinkResources/minifyEnabled in Android release builds #37

Open nmfisher opened 5 months ago

nmfisher commented 5 months ago

FilamentInterop.kt uses JNA on Android to resolve a handful of native methods (getting the native window, creating a resource loader, and a render callback).

In a standard Android release build, shrinkResources/minifyEnabled are set to true, but this will cause the following error at runtime:

E/flutter ( 6480): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, lateinit property _lib has not been initialized, null, e0.p: lateinit property _lib has not been initialized
E/flutter ( 6480):      at j.h.f(Unknown Source:140)
E/flutter ( 6480):      at z.i$a.a(Unknown Source:17)
E/flutter ( 6480):      at o.c.i(Unknown Source:18)
E/flutter ( 6480):      at o.c.j(Unknown Source:41)
E/flutter ( 6480):      at o.c.f(Unknown Source:0)

I haven't looked into this closely but clearly the minification is interfering with the dynamic resolution of the library and/or methods via JNA.

These two options are useful on Android to bring the release build size down, so we should investigate how we can use JNA with shrinkResources/minifyEnabled true (or alternatively, replace with JNI which I assume would avoid the issue).