[英]Get --dart-define environment variables in native iOS and Android
我正在嘗試找到一種方法來訪問本機 iOS 和 Android 代碼中--dart-define
提供的環境變量。
有沒有辦法做到這一點?
我已經嘗試過https://binary-studio.com/2020/06/23/flutter-3/中解釋的指南,但這不起作用,因為寫入生成的.xcconfig
的內容不是由=
分隔,而是由%3D
。 我得到了錯誤
error: .../ios/Flutter/DEFINEEnvironment.xcconfig:2: expected a ‘=’, but found % (in target 'Runner' from project 'Runner')
使用以下內容生成文件DEFINEEnvironment.xcconfig
MY_VAR%3DMY_VALUE
而不是MY_VAR=MY_VALUE
更新
這似乎正在發生,因為從傳遞給--dart-define
的 args 讀取時,它必須將 encoding =
轉換為%3D
。 而且我不知道如何防止這種情況發生
腳本似乎已更改,現在包含解碼字符串的必要代碼。
需要添加到 Scheme 的 post-action 腳本是:
function urldecode() { : "${*//+/ }"; echo "${_//%/\\x}"; }
IFS=',' read -r -a define_items <<< "$DART_DEFINES"
for index in "${!define_items[@]}"
do
define_items[$index]=$(urldecode "${define_items[$index]}");
done
printf "%s\n" "${define_items[@]}" > ${SRCROOT}/Flutter/DEFINEEnvironment.xcconfig
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.