如何混淆 Flutter 应用程序? [英] How to obfuscate Flutter apps?
问题描述
Flutter 的 wiki 提到混淆是一种选择处于发布模式.
然而,flutter build 命令没有相关选项 - 请参阅:flutter help -v build apk
Flutter's wiki mentions obfuscation is an opt-in in release mode.
And yet, the flutter build command has no relevant option - see:
flutter help -v build apk
我在这里遗漏了什么吗?
他们是否将混淆设置为默认设置?
混淆甚至与颤振相关吗?
Am I missing something here?
Did they make obfuscation the default?
Is obfuscation even relevant for flutter?
对此的任何指示将不胜感激.
Any pointers on this would be very appreciated.
推荐答案
需要混淆 - Flutter 应用程序知道其函数名称,可以使用 Dart 的 StackTrace 类显示.对混淆的支持测试不足.启用它:
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:
安卓版:
添加到文件 [ProjectRoot]/android/gradle.properties
:
extra-gen-snapshot-options=--obfuscate
<小时>
对于 iOS:
首先,编辑[FlutterRoot]/packages/flutter_tools/bin/xcode_backend.sh
:
找到 build aot
调用,并为其添加一个标志,
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}
定义为:
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
要应用您的更改,请在 [FlutterRoot] 中运行
To apply your changes, in [FlutterRoot], run
git commit -am "Enable obfuscation on iOS"
flutter
(在提交后运行flutter"重建颤振工具.)
(Running "flutter" after the commit rebuilds flutter tools.)
接下来,在您的项目中,将以下内容添加到 [ProjectRoot]/ios/Flutter/Release.xcconfig
文件:
Next, in your project, add following to [ProjectRoot]/ios/Flutter/Release.xcconfig
file:
EXTRA_GEN_SNAPSHOT_OPTIONS=--obfuscate
<小时>
PS:还没有尝试在 https://github.com/dart-lang/sdk/issues/30524
同样,正如@mraleph 所提到的,混淆没有经过很好的测试.
这篇关于如何混淆 Flutter 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!