0%

Dart define from file

需求

1
2
3
通过命令行传递参数
把App后缀,App名传给原生
baseURL传给flutter

实现

配置文件

release.json

1
2
3
4
5
{
"DEFINE_APP_NAME": "微信",
"DEFINE_APP_URL": "https://wechat.qq.com",
"DEFINE_APP_SUFFIX": ""
}

dev.json

1
2
3
4
5
{
"DEFINE_APP_NAME": "微信Dev",
"DEFINE_APP_URL": "https://dev.wechat.qq.com",
"DEFINE_APP_SUFFIX": ".dev"
}

命令行

1
2
3
4
5
flutter build ipa \
--export-method=ad-hoc \
--obfuscate \
--split-debug-info=./build/split-debug-info \
--dart-define-from-file=./env/dev.json
1
2
3
4
5
flutter build ipa \
--export-method=ad-hoc \
--obfuscate \
--split-debug-info=./build/split-debug-info \
--dart-define-from-file=./env/release.json

iOS 配置

project.pbxproj

1
PRODUCT_BUNDLE_IDENTIFIER = "com.wechat$(DEFINE_APP_SUFFIX)";

Info.plist

1
2
<key>CFBundleDisplayName</key>
<string>$(DEFINE_APP_NAME)</string>

Android 配置

build.gradle

1
2
applicationIdSuffix DEFINE_APP_SUFFIX
resValue "string", "app_name", DEFINE_APP_NAME

AndroidManifest.xml

1
android:label="@string/app_name"

Flutter 配置

1
String.fromEnvironment('DEFINE_APP_URL', defaultValue: '')

Android studio

1
--dart-define-from-file=./env/dev.json

还可以选中 Store as project file

–EOF–