简体   繁体   中英

Get --dart-define environment variables in native iOS and Android

I am trying to find a way to access the environment variables provided by --dart-define inside native iOS and Android code.

Is there any way to do this?

I have tried the guide explained in https://binary-studio.com/2020/06/23/flutter-3/ but that doesn't work as what gets written to the generated .xcconfig is not separated by = but instead by %3D . And I get the error

error: .../ios/Flutter/DEFINEEnvironment.xcconfig:2: expected a ‘=’, but found % (in target 'Runner' from project 'Runner')

The file DEFINEEnvironment.xcconfig gets generated with the following content MY_VAR%3DMY_VALUE instead of MY_VAR=MY_VALUE

UPDATE

This seems to be happening because when reading from the args passed to --dart-define it must be encoding = into %3D . And I don't know how prevent that from happening

It seems that the script has been changed and now includes the necessary code to decode the strings.

The post-action script that needs to be added to Scheme is:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM