chipweinberger / flutter_blue_plus

Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android, iOS, macOS
Other
727 stars 442 forks source link

Notes on Android12 release APK (Build APK) #148

Closed AlexQiulin closed 1 year ago

AlexQiulin commented 1 year ago

For Android 12, the APK file after the official package (Build APK) release cannot be searched for Bluetooth devices and the system Bluetooth solution cannot be opened 0

forte-sama commented 1 year ago

Something related happens to me, a debug build behaves like a charm, in release builds the app fails to discover services on the peripheral device. Happens specifically on Samsung s22 Ultra (Android 12).

Calvin-Ho commented 1 year ago

I have just fixed this in my own project.

You can still use shrinkResources and minifyEnabled as shown here in this snippet from my build.gradle:

...

buildTypes {
        release {
            signingConfig signingConfigs.release

            minifyEnabled true

            shrinkResources true

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

but you need to make sure to update your Proguard rules in android/proguard-rules.pro:

...

# flutter_blue_plus rules
-keep class com.boskokg.flutter_blue_plus.** { *; }
-keepclassmembernames class com.boskokg.flutter_blue_plus.* { *; }

This will prevent the classes and relevant members from being minified which means that they can be invoked as normal.

kashjack commented 1 year ago

It's working in my case, thank you

ChampiMagic commented 1 year ago

I dont have the "proguard-rules.pro" file on me android folder, were can I found it?

axelvugts commented 1 year ago

I dont have the "proguard-rules.pro" file on me android folder, were can I found it?

You have to manually create the file if it doesn't exist yet.

svprdga commented 1 year ago

buildTypes { release { signingConfig signingConfigs.release

        minifyEnabled true

        shrinkResources true

        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

but you need to make sure to update your Proguard rules in `android/proguard-rules.pro`:

...

flutter_blue_plus rules

-keep class com.boskokg.flutter_blue_plus.* { ; } -keepclassmembernames class com.boskokg.flutter_blue_plus. { ; }

Thank you so much for this information.

Without a doubt, this information should appear prominently in the README.md for this plugin.

zhaojun1217 commented 1 year ago

good issue , thank every one i used -keep class com.boskokg.flutter_blue_plus.* { ; } -keepclassmembernames class com.boskokg.flutter_blue_plus. { ; }