Android "SetupAndroid.bat" keeps giving this error "was unexpected at this time." UE 4-26

I’m at a complete loss here, I’m trying to setup Android Development and have tried 4 different methods even followed the Unreal Engine guide but every time I run the SetupAndroid.bat to install the NDK I get this error

C:\Program Files\Epic Games\UE_4.26\Engine\Extras\Android>SetupAndroid.bat
Android Studio Path: C:\Program Files\Android\Android Studio
Android Studio SDK Path: C:\Users\depre\AppData\Local\Android\Sdk
\Microsoft was unexpected at this time.

If anyone could shed some light onto what’s going on I would appreciate it.

I didn’t figure this out but I got it working without it anyway.

This happens because you have bracket symbols in user paths and whoever wrote this batch script didn’t thought of that.

Can be fixed by editing SetupAndroid.bat and wrapping %USERPATH% in quotes on line 56:

	echo Current user path: "%USERPATH%"

Second problem you may encounter is SetupAndroid.bat unable to locate sdkmanager.bat even if it actually exists in <SDKPath>\cmdline-tools\latest\bin\sdkmanager.bat
In this case you need to add this line at the beginning (next line after after @echo off):

setlocal EnableDelayedExpansion

and replace % with ! on lines 67 and 68:

	IF EXIST "!SDKMANAGER!" (
		echo Using sdkmanager: !SDKMANAGER!
7 Likes

Thanks, I was running this on Windows 11 at the time. I’m not sure if it still has the same issue but I re-installed Windows 10 and it worked just fine. Thanks again for the response, If I come across this issue again I’ll be sure to give this a shot.

these are already set up like this in the .bat I have, why else might this be the issue

image

Thank you so much. I wouldn’t have figured this out without you!

did you ever figure this out? I just ran into the same issue

you could try why this guy suggests here, video is in gernman so put on subs
Tutorial for Unreal Engine 5: Develop and install Virtual Reality App for the Oculus/Meta Quest (2) - Platform & Builds / XR Development - Unreal Engine Forums

Wrapping %USERPATH" in quotes on line 56 fixed the issue for me, thanks a bunch @grinchfox

1 Like

This helped massively, thank you!

Thank you so much