Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btleplug on Android crashes on release builds #272

Closed
qdot opened this issue Oct 22, 2022 · 3 comments
Closed

btleplug on Android crashes on release builds #272

qdot opened this issue Oct 22, 2022 · 3 comments
Assignees
Labels
android Issues related to the android core bug Something isn't working

Comments

@qdot
Copy link
Contributor

qdot commented Oct 22, 2022

Describe the bug

  1. Integrate btleplug in a flutter application (See Add Android Support #8)
  2. Build application in release mode
  3. 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.

@qdot qdot added bug Something isn't working android Issues related to the android core labels Oct 22, 2022
@qdot qdot self-assigned this Oct 22, 2022
@qdot qdot changed the title btleplug on Android crashed on load btleplug on Android crashes on release builds Oct 22, 2022
@qdot qdot mentioned this issue Oct 22, 2022
@qdot
Copy link
Contributor Author

qdot commented Oct 22, 2022

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.

@qdot
Copy link
Contributor Author

qdot commented Oct 22, 2022

Slightly simpler catch all that doesn't require a proguard rules file:

    buildTypes {
        release {
            signingConfig signingConfigs.debug

            minifyEnabled true
            shrinkResources false
        }
    }

@qdot
Copy link
Contributor Author

qdot commented Oct 22, 2022

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.** { *; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Issues related to the android core bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant