Why is SetupAndroid.bat failing with default setup directories?

Steps to Repro:

  1. Open Epic Games Launcher on Windows
  2. Uninstall any existing copies of Unreal Engine
  3. Download and Install Engine version 4.25.1
  4. Launch 4.25.1 to ensure installation is correct
  5. Shutdown both the Engine and the Epic Games Launcher application
  6. Follow all steps exactly in [Setting Up Android SDK and NDK for Unreal | Unreal Engine Documentation][1] using default installation locations, making sure to download Android Studio 3.5.3 (android-studio-ide-191.6010548-windows.exe)

Expected Results:

Running the SetupAndroid.bat script in Step 3.3 results in being prompted to accept the Android SDK license agreement.

Actual Results:

303675-ue4-25-setupandroid.png

Context

After uninstalling 4.24 and installing 4.25, I pulled up the [Setting Up Android SDK and NDK for Unreal | Unreal Engine Documentation][3] page so I could be certain that my android environment was set up for the new engine. I’ve followed the instructions here to a T, including the recommendations to completely uninstall CodeWorks and any NDK components. CodeWorks was installed at its default location, and I have made sure the completely delete the C:\NVPACK folder.

I followed the rest of the instructions on the documentation page to a T as well. I made sure to download Android Studio 3.5.3 specifically, the exe file downloaded was as listed in the documentation screenshot:

android-studio-ide-191.6010548-windows.exe.

Following the setup instructions to the letter, installing only at default installation directories, I have come across a total blocker at Step 3.3:

The script is supposed to prompt me to accept a license agreement, but instead the script outputs the following (I’ve replaced my username with <USERFOLDER>:

C:\Program Files\Epic Games\UE_4.25\Engine\Extras\Android>SetupAndroid.bat
Android Studio Path: "C:\Program Files\Android\Android Studio"
Android Studio SDK Path: C:\Users\<USERFOLDER>\AppData\Local\Android\Sdk
\Android\android-sdk\platform-tools was unexpected at this time.

And that’s it, the script doesn’t run beyond that. Any help in getting me past this in my Unreal Android Setup would be greatly appreciated, thanks for reading! :slight_smile:

3 Likes

Well, I figured out by dropping in “echo” statements all over the SetupAndroid.bat file that my error is occuring somewhere around Line 55 in the Batch script.

If I alter the script by adding echo %ERRORLEVEL% both before and after the line where.exe /Q adb.exe, command prompt should print out the value stored there both times. As you’ll see in the command prompt screenshot, %ERRORLEVEL% returns both 0 and then it returns 1. So it follows then, that the next conditional statement IF "%ERRORLEVEL%" NEQ "0" should return true since %ERRORLEVEL% is indeed not 0, it’s 1, but neither of the code blocks whether true or false execute the code within them.

304432-ue-4-25-1-batcheditoutput.png

So with this altered batch file, I’d expect the command prompt to read “ERRORLEVEL is indeed NOT zero” since we just checked the value of %ERRORLEVEL% and you can see the 0 and 1 in the above screenshot. I think it’s very weird that it is here of all places that the script seems to fail, outputting instead \Android\android-sdk\platform-tools was unexpected at this time.

You can clearly see that my two echo %ERRORLEVEL% statements are working correctly. I just don’t really understand why the following conditional statement is failing, especially after commenting out the original statements and just trying to print some string values.

I guess I’m going to give up on this and manually download NDK and manually target the SDK, NDK, and JDK directories. Would still appreciate any help from anyone who might have a clue as to what’s going on here.

Hey there,

Did you manage to suss this?
I try and run the batch file and it closes immediately after it’s run.
Please could you tell me what JDK version you have, I had to download mine from Oracle, which is V14. Maybe this is not the right version to go with Android Studio 3.5.3.

Must admit this all seems quite complicated on Epic’s and Androids behalf.

All the best and stay safe =]

Nope, I have not been able to figure this out, and it is still very much a mystery to me. I haven’t downloaded JDK manually yet because I don’t know what’s compatible with Android Studio 3.5.3, and I don’t really know where to look for that info, especially in regards to how it relates to UE4.25.

Best of luck friend, please let me know how it goes. I hope other people can come across this thread too, I was certain no one would see it at all :slight_smile:

That’s a shame, Dude, don’t understand why these things are so complicated.

Found the JDK on Oracles site, though there’s videos out stating you don’t need it as it’s already embedded in AS3.5.3, the version I got was Oracle, JDK14, think this is way too high and should be JDK8.
Though, as always, there’s so much conflicting information available.

Ok, back on the trail, and removed everything pertaining to Android Studio and NVIDIA Codeworks.
Check out your Environmental Variables and delete all entries relating to Android prior to reinstalling AS.

Will keep you posted, let me know if you have any further luck too, please?

All the best and stay safe =]

EPIC:
If you come across this issue, then please help the both of us out; Thank you in hope!?!

Please see:
How to completely uninstall Android Studio from windows(v10)? - Stack Overflow.

Also under Project Settings>Platforms - Android SDK: SDKConfig, reset the location of the file paths to blank for SDK, NDK & JDK.

With all this in mind, I’ll try and establish the correct JDK, though as mentioned before in a post and video this is not required.

In addition, all the videos I’ve seen, state what Epic say in their docs, however, there SetupAndroid.bat file always works, this has never upto now anyway worked for me, so cross fingers, here I go again, lol.

Hey Mike,

Ok, got this sussed yesterday and now have app on Samsung S8.

This is what I did…

  1. Remove everything pertaining to Android Studio and NVIDIA Codeworks. Check out your Environmental Variables and delete all entries relating to Android prior to reinstalling AS.
    Also follow this helpful link on Android Studio removal:
    How to completely uninstall Android Studio from windows(v10)? - Stack Overflow.

  2. Follow this really helpful video upto the point of running the dreaded and anti climatic SetupAndroid.bat file.
    UNREAL ENGINE 4.25.1 PACKAGING FOR ANDROID TUTORIAL UPDATED! - YouTube

In addition, when you open up a UE4 project file, go to Project Settings>Platforms - Android SDK: SDKConfig, reset the location of the file paths to blank for SDK, NDK & JDK.
N.B. My install of Android Studio was slightly different to the video, it ask me for Intel x86 Emulator Accelerator (HAXM installer) and Android Emulator; I checked these too.

  1. Try to run the bat file, though I should think it’ll still flash up briefly, which again is more than annoying.

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

  3. Check Environmental Variables are like the screenshot in relation to any Android as shown:

  1. At this point you may want to check your Registry entries and ensure for Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Android Studio, that the Path and SdkPath are correctly set to Drive:\Users\username\Documents\AndroidStudio and Drive:\Users\username\Documents\ANDROIDSDK respectively.

  2. Now for the fun bit, back to UE4.25, open your Project and access Project Settings, type sdk in search window.
    Under Platforms - Android, accept SDK License.
    Under Platforms - Android SDK:
    Location of Android SDK> Drive:/Username/Documents/ANDROIDSDK
    Location of Android NDK> Drive:/Username/Documents/ANDROIDSDK/ndk/21.1.6352462
    Location of JAVA> Drive:/Username/Documents/AndroidStudio/jre

  3. Build your UE4.25 Android project, and run the, Install_PodgerAndroid425_0-armv7.bat, file in the Build folder under your Project folder.
    Fingers crossed this will work for you?! Please, let me know how you get on.

All the best and stay safe =]

Hey there!

I’m having the same exact issue.

Seems like its a bug with the recent 4.25.1 hotfix because everywhere I look, people with 4.25 are doing this succesfully.

Please update if you manage to find a convenient fix!

Hey patchmw,

I had real issues with it, but I found the solution below, did you follow the steps?

I had the same issue, for me the problem was the line 57 of SetupAndroid.bat: setx PATH "%USERPATH%;%PLATFORMTOOLS%".
I printed out USERPATH with echo and it was already a quoted string, so it results in a string that is partly double quoted.
What fixed it for me was taking a substring of USERPATH with removed quotes at the beginning and the end:

setx PATH "%USERPATH:~1,-1%;%PLATFORMTOOLS%"

Thank you! Your advice helped me. You awesome

Hey Guys, I struggled with this fro 2 days then I found this very useful video, It works like a charm Let’s all give him a thumbs up guys

1 Like

Worked for me as well, you are awesome indeed

Thnaks This worked very well!

Hey OP here, so what ended up working for me was this video posted by someone else responding to my forum thread :slight_smile:

Okay, all of this just boils down to poor programming on Epic’s part.

If you have any path with a space in it in your PATH variable, the script barfs.
Thankfully I’ve modified the default path for most things, so it’s not an issue, you may have more or less luck.

The reason the videos above work is that they’re installing to a path with no spaces.

Essentially:

  • Winkey + R
  • “Environment Variables”
  • “Environment Variables” button at the bottom right
  • in “user variables for you” find PATH
  • hit edit
  • take a screenshot incase you need them back
  • remove any path with a space in it ( c:\program files, c:\program files (x86), c:\whatever\my awesome stuff)

I’m brand new to the forums so could someone please tag a member of staff to get this fixed?
Thanks.

Disappointed though.
Just switched over from 8 years of Unity because I’m stick of this poorly tested, nonworking, divergent mess of a system. Head in the game please.

Okay, all of this just boils down to poor programming on Epic’s part.

If you have any path with a space in it in your PATH variable, the script barfs.
Thankfully I’ve modified the default path for most things, so it’s not an issue, you may have more or less luck.

The reason the videos above work is that they’re installing to a path with no spaces.

Essentially:

  • Winkey + R
  • “Environment Variables”
  • “Environment Variables” button at the bottom right
  • in “user variables for you” find PATH
  • hit edit
  • take a screenshot incase you need them back
  • remove any path with a space in it ( c:\program files, c:\program files (x86), c:\whatever\my awesome stuff)

I’m brand new to the forums so could someone please tag a member of staff to get this fixed?
Thanks.

Disappointed though.
Just switched over from 8 years of Unity because I’m stick of this poorly tested, nonworking, divergent mess of a system. Head in the game please.

Thanks so much finally got it to work by doing this!

In my case, this has to do with the directory “Program Files (x86)” being present in my path. I get the error “\Microsoft was unexpected at this time” Your path might contain this directory too if you are using a 64-bit version of Windows.

The crux of the issue is those parentheses around the “(x86)”, the batch file can’t handle it. I’ve attempted a fix but I’m not great at .bat syntax so I’ll let you know how it goes.