btleplug on Android crashes on release builds
qdot opened this issue · comments
Describe the bug
- Integrate btleplug in a flutter application (See #8)
- Build application in release mode
- Run on phone
Expected behavior
Application runs
Actual behavior
Application crashes immediately on startup
Additional context
This crash looks very similar to completely forgetting to add the droidplug.aar file and running the debug version. This points to dead code elimination possibly cutting out the aar file entirely, since it's only linked on the other side of native binaries current. We probably need some sort of glue method that does nothing but creates/calls objects in the aar anyways.
First stop gap: Just turn off all code stripping. This seems to work.
In the android/app build.gradle:
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
minifyEnabled true
// Some solutions include "useProguard true" here but that caused my build to not work
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
In android/app/proguard-rules.pro:
-keep class ** { *; }
Obviously this isn't ideal, as we'd like to only keep the symbols out of our AAR, but I'm still figuring out the rules for that.
Slightly simpler catch all that doesn't require a proguard rules file:
buildTypes {
release {
signingConfig signingConfigs.debug
minifyEnabled true
shrinkResources false
}
}
Ok, this is all about getting the proguard rules correct. Turned out that I was missing some extra symbols for the jni-utils-rs library.
For build.gradle:
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
proguard-rules.pro:
#Flutter Wrapper - Only needed if using flutter
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }
#btleplug resources
-keep class com.nonpolynomial.** { *; }
-keep class io.github.gedgygedgy.** { *; }