Flutter Blue Example not managing to find through Scan both my bluetooth PC, other Android phone and iOS

Viewed 3198

Flutter Blue is unable to find all my bluetooth devices running the example application they offered. No error messages are presented. The Bluetooth adapter is ON and all devices are BLE compatible.

https://gyazo.com/27f907034570f860997026ed295be026

I've tried both pairing the devices through the external Android tool and testing without pairing. No devices are being shown.

_Scan() {
print('STARTED');

if (!isScanning) {
  print('SCANNING');
  setState(() { isScanning = true; });
  scanSubscription = flutterBlue.scan().listen((scanResult) {
    print('Scan Result');
    print('localName: ${scanResult.advertisementData.localName}');
    print(
        'manufacturerData: ${scanResult.advertisementData
            .manufacturerData}');
    print('serviceData: ${scanResult.advertisementData.serviceData}');
  }, onDone: _StopScan);
}
  }

The example app does its buffering animation and the stops with no devices found.

The intended behavior is to find devices and print them as a list on the main app screen.

1 Answers

I was experiencing this issue when testing on a device with the --release flag.

Apparently there is an issue with the minification of flutter blue. There are two ways of working around the problem, as listed in this issue: https://github.com/pauldemarco/flutter_blue/issues/662

In android/app/build.gradle you can disable minifaction:

android {
    ...
    buildTypes {
        release {
            signingConfig signingConfigs.debug
            shrinkResources false
            minifyEnabled false
        }
    }

OR you can create a proguard rule that prevents flutter_blue from minimizing: In android/app/build.gradle:

android {
    ...
    buildTypes {
        release {
            signingConfig signingConfigs.debug
            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
        }
    }

and create a file at android/app/proguard-rules.pro with the following:

-keep class com.pauldemarco.flutter_blue.** { *; }
Related