fengqiangboy / flutter-nordic-dfu

Flutter Nordic dfu
MIT License
109 stars 76 forks source link

Android 12 Support #41

Open Montvydas opened 2 years ago

Montvydas commented 2 years ago

As discussed in the Android-DFU-Library github page issue 315, there was an issue with the library on Android 12, which by now is fixed and the fix is released. This flutter library does not have the fix and thus it cannot be used on Android 12. The required changes are minimal, only needing to update the Flutter library with the new releases from the Nordic Semiconductors.

Montvydas commented 2 years ago

Just to let you know, I have managed to do this myself here, since it only required changing file android/build.gradle, I updated to version 1.12.1-beta01 since that was the latest one and I no longer get the mentioned error. This however adds some other issues. Firstly, it changes the way, how within Android one requests permissions as starting Android 12 if one requests Bluetooth permission, it will be rejected automatically, instead one needs to specifically ask for bluetoothScan, bluetoothConn and bluetoothAdvertise permissions e.g. using the permissions permission_handler library one could request these permissions:

  final kPermissions = const <Permission>[
    Permission.bluetoothScan,
    Permission.bluetoothConnect,
    Permission.bluetoothAdvertise,
    Permission.locationWhenInUse,
  ];

Manifest will also have to change as explained here and it seems that the permission handling will need to check wether the android version is below 12 or above 12.

There is still some sort of unknown issue: I manage to start DFU uploading and it gets to the point of printing "Uploading firmware...", followed by uploading the firmware all the way until 100% (know this from using the DefaultDfuProgressListenerAdapter) and then nothing happens, startDfu method basically never exits. I tried waiting like 10min but the app simply gets blocked there and if I cancel the DFU upload at this point the board is bricked and required flashing the firmware using a cable. Has anyone experienced this before?

GoodOldBatman commented 2 years ago

Thanks for pointing out that one can simply replace the Android Dfu Library! They recently updated to 2.0.2. Together with your other suggestions, I could get it to work with Android 12 (Pixel 4).

I have not experienced that the DFU got stuck after 100 % and the device getting bricked.

Montvydas commented 2 years ago

So the device being bricked is the issue of single bank approach, where the old firmware is deleted before downloading the new one. With dual bank setup this shouldn't happen.. Yet I would still have the issue of unsuccessful update.

Edit: I haven't tried the new version 2.0.2, since at the time the latest was 1.12.1-beta01, so potentially the problem was within the Nordic SDK itself, I will update this issue after trying out the latest version some time later.

Montvydas commented 2 years ago

Ok, so I tried using 2.0.2 however still had the same problem. I also tried nordic-dfu library (since it seems that flutter-nordic-dfu is no longer mainated) and experienced the same problem. There is an issue raised already which outlines the same problem I am having here :/

haoyuant commented 2 years ago

Any update on the new release?