2

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

1
  • 1
    Hi) sorry for this confusion) I've updated article on medium long time ago, and even published a new article regarding changes in 1.20) but for some reason article in our blog still wasn't updated ( Commented Mar 3, 2021 at 9:14

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.