Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude files, classes, libraries or packages from dart obfuscation in flutter?

I found this about dart obfuscation in flutter, but it only says how to enable obfuscation. I tried looking up in what seems to be the snapshot generator arguments here, but the only arguments exposed regarding obfuscation are:

--obfuscate
--save-obfuscation-map=<map-filename>
like image 804
josue.0 Avatar asked Sep 20 '25 06:09

josue.0


2 Answers

I know this answer is super late, but for whoever that needs this now:

To prevent certain classes from getting obfuscated, add @pragma("vm:entry-point") above the class definition.

Doing this will make the class name survive obfuscation.

e.g.:

@pragma("vm:entry-point")
class MyAwesomeClass {
  const MyAwesomeClass(this.id, tnis.name);

  int id;
  String name;
}

Reference: https://github.com/dart-lang/sdk/blob/master/runtime/docs/compiler/aot/entry_point_pragma.md#classes

like image 66
OutdatedGuy Avatar answered Sep 23 '25 06:09

OutdatedGuy


As far as I know, it's not possible to only obfuscate part of your application. I don't recall that ever being requested by a Google team using Flutter, so I would be extremely surprised if this was possible.

like image 30
Ben Konyi Avatar answered Sep 23 '25 07:09

Ben Konyi