flutter-android-background icon indicating copy to clipboard operation
flutter-android-background copied to clipboard

Obfuscated apk does not work in Flutter 2.2.0+, worked in Flutter 1.22.6

Open gazialankus opened this issue 3 years ago • 1 comments

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

gazialankus avatar Aug 22 '21 01:08 gazialankus

This is a very curious case. When obfuscation is enabled the parameter comes in as an Int. So, as Long fails. image Changing it toval 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... image

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.

gazialankus avatar Aug 22 '21 02:08 gazialankus