1

I recently started running into an issue, where, when building my Flutter in release mode to deploy to Play Console's internal testing track, some of my functions in Flutter started failing.

For context, I have EventChannels that stream data from a native function to Flutter, from which I construct a Flutter object.

After countless hours of investigation, it turned out that, in debug mode, the JSON string I'm constructing in Kotlin, contains the correct keys, however, when doing the same thing in release, the keys turn to a:, b:, c:, etc.

At this point in time, I've got no obfuscation enabled in the app, and I'm not too sure why this would have suddenly broke.

I can't cater for the actual names, and alphabetical values in my toJson() function on my class, so want to know how, in release, can I get my parameter values back?

The kotlin class that's encoded to JSON looks like this:

class ScanResponseModel(var name: String, var mac: String, var axis: String, var number : String)

The json output for this, in DEBUG, looks like this:

[{
    "name":"2325",
    "mac":"D4:1C:32:33:EE:1F",
    "axis":"left",
    "number":"0002325"
}, {
    "name":"2122",
    "mac":"DC:20:3F:E7:05:B7",
    "axis":"right",
    "number":"0002122"
}]

The exact same output in RELEASE, looks like this:

[{
    "a":"2325",
    "b":"D4:1C:32:33:EE:1F",
    "c":"left",
    "d":"0002325"
},
{
    "a":"2122",
    "b":"DC:20:3F:E7:05:B7",
    "c":"right",
    "d":"0002122"
}]
Richard Heap
  • 48,344
  • 9
  • 130
  • 112
JadedEric
  • 1,943
  • 2
  • 26
  • 49
  • Why are you converting your native object to JSON, when you could encode it using the traditional `StandardMessageCodec`? – Richard Heap Dec 11 '22 at 13:31
  • @RichardHeap because I was unaware of this. i'm rather new to Flutter and jumped on a project to help out. do you perhaps have an example of how to use this. a quick search led me to a medium article and it states i have to encode the entire method call? what i'm doing is, listening for bluetooth devices via a 3rd party vendor's SDK, and I'm encoding the value in their supplied callback function which I subsequently added to a sink, I don't see how this codec will allow me the same functionality, or am I missing something? – JadedEric Dec 11 '22 at 13:55
  • Since you don't show any of your native code, it's hard to say, but it looks like you should just make your native value into an `ArrayList>` which you'll be able to drop directly into the event channel. It will appear at the Dart end as a `List>`. No need for JSON. – Richard Heap Dec 11 '22 at 14:31
  • @RichardHeap i'm going to try this, thanks. – JadedEric Dec 11 '22 at 15:28

0 Answers0