flutter-android-background
flutter-android-background copied to clipboard
Obfuscated apk does not work in Flutter 2.2.0+, worked in Flutter 1.22.6
I build my apk with obfuscation
flutter build apk --obfuscate --split-debug-info=debuginfo_to_deobfuscate
With this, the background service's persistent notification appears when using Flutter 1.22.6. After upgrading to Flutter 2.2.0, the persistent notification stopped appearing and the app does not work in the background anymore. I set minifyEnabled false
in app/build.gradle in case it's R8 that's the problem.
Doing either one of the things below make the persistent notification appear again:
- build using
flutter build apk
, without obfuscation - downgrade Flutter to 1.22.6
This is a very curious case. When obfuscation is enabled the parameter comes in as an Int. So, as Long
fails.
Changing it to
val callbackRawHandle = (method.arguments as Int).toLong()
works in this case.
However, you cannot bulid without obfuscation anymore as it comes in as a Long. So, as Int
fails now. You have to change it back to as Long
again...
So I did this and it works both in obfuscated and non-obfuscated builds:
val callbackRawHandle = if (method.arguments is Long)
method.arguments as Long
else
(method.arguments as Int).toLong() // flutter build apk --obfuscate
Will send a PR now.