How to obfuscate Flutter apps?

前端 未结 5 1696
独厮守ぢ
独厮守ぢ 2020-12-29 06:12

Flutter\'s wiki mentions obfuscation is an opt-in in release mode.
And yet, the flutter build command has no relevant option - see:
flutter he

5条回答
  •  太阳男子
    2020-12-29 06:54

    Obfuscation is needed - a flutter app knows its function names, which can be shown using Dart's StackTrace class. There's under-tested support for obfuscation. To enable it:


    For Android:
    Add to the file [ProjectRoot]/android/gradle.properties :

    extra-gen-snapshot-options=--obfuscate
    

    For iOS:
    First, edit [FlutterRoot]/packages/flutter_tools/bin/xcode_backend.sh:
    Locate the build aot call, and add a flag to it,

    ${extra_gen_snapshot_options_or_none}
    

    defined as:

    local extra_gen_snapshot_options_or_none=""
    if [[ -n "$EXTRA_GEN_SNAPSHOT_OPTIONS" ]]; then
      extra_gen_snapshot_options_or_none="--extra-gen-snapshot-options=$EXTRA_GEN_SNAPSHOT_OPTIONS"
    fi
    

    To apply your changes, in [FlutterRoot], run

    git commit -am "Enable obfuscation on iOS"  
    flutter  
    

    (Running "flutter" after the commit rebuilds flutter tools.)

    Next, in your project, add following to [ProjectRoot]/ios/Flutter/Release.xcconfig file:

    EXTRA_GEN_SNAPSHOT_OPTIONS=--obfuscate
    

    PS: Haven't tried the --save-obfuscation-map flag mentioned at https://github.com/dart-lang/sdk/issues/30524
    Again, obfuscation isn't very well tested, as mentioned by @mraleph.

提交回复
热议问题