# Why is SetupAndroid.bat failing with default setup directories?

**URL:** <https://forums.unrealengine.com/t/why-is-setupandroid-bat-failing-with-default-setup-directories/466313>\
**Category:** Mobile\
**Tags:** UE4-25, setup, unreal-engine, Android, UE4, question\
**Created:** [June 6, 2020, 4:42pm UTC](https://forums.unrealengine.com/t/why-is-setupandroid-bat-failing-with-default-setup-directories/466313 "2020-06-06T16:42:38Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![anonymous\_user\_1e62d6701](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1e62d6701](https://forums.unrealengine.com/u/anonymous_user_1e62d6701)\
**Post date:** [February 4, 2021, 5:35pm UTC](https://forums.unrealengine.com/t/why-is-setupandroid-bat-failing-with-default-setup-directories/466313/21 "2021-02-04T17:35:13Z")

</div>

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%.

---

<div class="post-metadata">

**Author:** ![Kavan](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kavan/32/1194623_2.png) [@Kavan](https://forums.unrealengine.com/u/Kavan)\
**Post date:** [February 24, 2021, 11:35pm UTC](https://forums.unrealengine.com/t/why-is-setupandroid-bat-failing-with-default-setup-directories/466313/22 "2021-02-24T23:35:48Z")

</div>

> 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!

---

<div class="post-metadata">

**Author:** ![lukas.vilim](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@lukas.vilim](https://forums.unrealengine.com/u/lukas.vilim)\
**Post date:** [March 1, 2021, 2:50pm UTC](https://forums.unrealengine.com/t/why-is-setupandroid-bat-failing-with-default-setup-directories/466313/23 "2021-03-01T14:50:35Z")

</div>

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](https://docs.microsoft.com/en-us/windows/win32/procthread/environment-variables). 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!

---

<div class="post-metadata">

**Author:** ![mhazani](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mhazani/32/725283_2.png) [@mhazani](https://forums.unrealengine.com/u/mhazani)\
**Post date:** [March 9, 2021, 8:26am UTC](https://forums.unrealengine.com/t/why-is-setupandroid-bat-failing-with-default-setup-directories/466313/24 "2021-03-09T08:26:31Z")

</div>

bless you. solved it for me.

---

<div class="post-metadata">

**Author:** ![ImmortalB563](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ImmortalB563](https://forums.unrealengine.com/u/ImmortalB563)\
**Post date:** [July 12, 2021, 5:55am UTC](https://forums.unrealengine.com/t/why-is-setupandroid-bat-failing-with-default-setup-directories/466313/25 "2021-07-12T05:55:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![AnderGraw](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AnderGraw](https://forums.unrealengine.com/u/AnderGraw)\
**Post date:** [July 21, 2021, 4:24pm UTC](https://forums.unrealengine.com/t/why-is-setupandroid-bat-failing-with-default-setup-directories/466313/26 "2021-07-21T16:24:53Z")

</div>

Thank you SO MUCH. That was exactly the problem.

---

<div class="post-metadata">

**Author:** ![vnhllsng](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@vnhllsng](https://forums.unrealengine.com/u/vnhllsng)\
**Post date:** [August 15, 2021, 9:23pm UTC](https://forums.unrealengine.com/t/why-is-setupandroid-bat-failing-with-default-setup-directories/466313/27 "2021-08-15T21:23:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mike\_patterson](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mike\_patterson](https://forums.unrealengine.com/u/mike_patterson)\
**Post date:** [August 15, 2021, 10:52pm UTC](https://forums.unrealengine.com/t/why-is-setupandroid-bat-failing-with-default-setup-directories/466313/28 "2021-08-15T22:52:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Good\_GD](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Good\_GD](https://forums.unrealengine.com/u/Good_GD)\
**Post date:** [June 8, 2022, 9:40pm UTC](https://forums.unrealengine.com/t/why-is-setupandroid-bat-failing-with-default-setup-directories/466313/29 "2022-06-08T21:40:23Z")

</div>

thanks this fix it for me in ue5

---

<div class="post-metadata">

**Author:** ![RabbitRun01](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rabbitrun01/32/584858_2.png) [@RabbitRun01](https://forums.unrealengine.com/u/RabbitRun01)\
**Post date:** [November 21, 2022, 4:09pm UTC](https://forums.unrealengine.com/t/why-is-setupandroid-bat-failing-with-default-setup-directories/466313/30 "2022-11-21T16:09:30Z")

</div>

Thanks a lot!

[Previous page](https://forums.unrealengine.com/t/why-is-setupandroid-bat-failing-with-default-setup-directories/466313.md?page=1)
