Why is SetupAndroid.bat failing with default setup directories?

For Windows 64-bit users getting the “_ was unexpected at this time” error, add usebackq to line 52:

FOR /F "tokens=2* usebackq" %%A IN ('REG.exe query "%KEY_NAME%" /v "%VALUE_NAME%"') DO (set USERPATH=%%B)

The error is caused by parentheses and spaces in your %PATH%.

7 Likes
  1. Open Android
    Studio>File>Settings>Appearance &
    Behaviour>System Settings>Android SDK
    and select the SDK Tools tab. Uncheck,
    Hide Obselete Packages and check, Show
    Package Details (Bottom right on
    page). Check, NDK (Side by
    side)>21.1.6352462, and check,
    CMake>3.10.2.4988404 Hit apply, then,
    ok, and exit AS.

You’re a champ!

Hey guys, I didn’t find here a relevant answer yet so I’m adding my two cents to the discussion.

I can confirm that if you see some nonsense error message like /Microsoft was unexpected at this time it is most probably related to the spaces or special characters in your PATH environmental variable. The script is attempting to parse the paths by hand and fails to enclose the result in double quotes which thrashes the PATH effectively.

If you don’t want to randomly uninstall software from your system without much explanation of the real issue and if you are not afraid of modifying the epics SetupAndroid.bat script you can fix it with following:

Before

line about 52: FOR /F "tokens=2*" %%A IN ('REG.exe query "%KEY_NAME%" /v "%VALUE_NAME%"') DO (set USERPATH=%%B)

After

line about 52: FOR /F "tokens=2*" %%A IN ('REG.exe query "%KEY_NAME%" /v "%VALUE_NAME%"') DO (set USERPATH="%%B")

Note: Just add quotes to the last bit.

Keep in mind that I can’t warrant that this will work for everyone but it is my workaround for 4.25.3-release. This might be already fixed in more up-to-date versions. Hope someone finds it useful. Cheers!

bless you. solved it for me.

Holyshit Man this worked me. Thank You so so much i wasted so much time and watched some youtube tutorials on that but none of them worked. Life saver

Thank you SO MUCH. That was exactly the problem.

Why isn’t this the right answer? It totally worked for me where the purported correct answer didn’t.

Sorry, this is me not knowing how to change the accepted answer. Hopefully corrected now!

thanks this fix it for me in ue5

Thanks a lot!