NDKROOT environment variable not handled correctly in Windows, for Android

I get an error when I try to build a game for Android. While reading the log I noticed something strange about the path of ndk-build.cmd (see the slash before ndk-build.cmd):

Running: C:\Program Files\Android NDK\android-ndk-r10b/ndk-build.cmd NDK_DEBUG=1

In this case the NDKROOT variable was: C:\Program Files\Android NDK\android-ndk-r10b
I tried changing it by adding a backslash at the end, so it became C:\Program Files\Android NDK\android-ndk-r10b\
This resulted in:

Running: C:\Program Files\Android NDK\android-ndk-r10b\/ndk-build.cmd NDK_DEBUG=1

Another had this in his log (there is no separator after “C:”):

Running: C:NVPACKandroid-ndk-r9c/ndk-build.cmd NDK_DEBUG=1

It may not be the reason for the failed build (who knows), but in any case it seems the way the path is handled needs to be fixed.

Additional info:

I just downloaded and setup everything according to the guide, all up to date. Using: Nexus 4 (Android 4.4), UE4 4.4.3, Windows 7 x64, Android SDK x32 rev. 23.0.2 / 20, JDK x64, Android NDK r10b (x64 for windows, x32 for output).

I did not use the automated TADP to install all the SDK’s etc. I did it manually and set all environment variables. (However I believe this has nothing to do with the problem). I have followed all steps from the guides (https://docs.unrealengine.com/latest/INT/Platforms/Android/index.html)

I tried ATC and ETC1 texture compression. I tried building the Sun Temple Mobile project and also my own project.

Log:

LogPlayLevel:Display: Running: C:\Program Files\Android NDK\android-ndk-r10b/ndk-build.cmd NDK_DEBUG=1
LogPlayLevel:Display: BuildCommand.Execute: ERROR: BUILD FAILED
LogPlayLevel:Display: Program.Main: ERROR: AutomationTool terminated with exception:
LogPlayLevel:Display: Program.Main: ERROR: Exception in UnrealBuildTool: ERROR: ndk-build failed [NDK_DEBUG=1]
LogPlayLevel:Display: Stacktrace: at UnrealBuildTool.Android.UEDeployAndroid.MakeAPK(String ProjectName, String ProjectDirectory, String OutputPath, String EngineDirectory, Boolean bForDistribution, String CookFlavor)
(…)

Edit:
Full log: [link text][1]
DxDiag: [link text][2]

16383-build+log.txt (481 KB)
[2]: 16384-dxdiag.txt (26.2 KB)

Howdy

Thank you for reporting this error. I am going to need a bit more information from you before i can investigate what you may be seeing. Could you attach your DXdiag and your project log files to this post? Could you also include a full build failed log? Any additional information would be greatly appreciated.

Thanks and have a great day!

Hi!

Thanks for your reply! I attached the build log and the DxDiag. I hope these help!

Enjoy your day,
Stan

The env vars are fine (the logging unfortunately messes up with back slashes, and that forward slash is fine). The problem is almost certainly that you have installed SDK 20. Something in there broke ndkbuild/ant (and we aren’t the only ones bitten by it). See this post:

We are also going to put into into the GettingStarted page that will say that SDK 20 is bad news.

Josh

Thanks! However, the problem has a different cause in my case (not sure what). I deleted SDK 20 and installed 19. I also deleted the NDK r10b and installed 9c (this is the version that TADP uses). I am still getting the same error:
“Exception in UnrealBuildTool: ERROR: ndk-build failed:”
Note that my problem is not with ANT, as it is in the other thread.

P.S. You can download arbitrary versions of the NDK by modifying the URL (important parts to modify are r9c, windows, _64 and zip): https://dl…com/android/ndk/android-ndk-r9c-windows-x86_64.zip

Hmm, well I’m at a loss without more output from ndk-build. I thought it would output the logging, but it’s possible because of the way we have to launch ndk-build (with a pop window, for some strange Windows file handle reason), it’s hiding the output. Try this:

Find this in UEDeployAndroid.cs:
NDKBuildInfo.UseShellExecute = true;

Set it to false, or comment it out, then try again.

Josh

I can’t find this file UEDeployAndroid.cs anywhere. Where should I look?
(Does this mean I have to download the UE4 souce and build from it? )

Howdy

Sorry about the lack of response. Would you still be running into this issue when you are packaging for Android? any information would be greatly appreciated.

Thanks and have a great day!

Hi,
I assume you were doing great work on the engine instead of replying, so no problem :slight_smile:

Using UE 4.4 for SunTemple, on Windows 7, on device Nexus 4 with Android 4.4.

I used the TADP tool to install the Android NDK, instead of using the one I had installed manually before (I also installed cygwin with TADP). Not sure if this is the reason, but the build managed to get a few steps further.
Now it “successfully” builds the APK (19.6MB), but then fails when it tries to upload it on the device. It’s a stupid error - it does not recognize the path because of space in “program files”:
'C:\Program' is not recognized as an internal or external command, operable program or batch file. (Check the attached log. [link text][1] )

It seems to me that the more thoroughly tested case is when everything is installed in "C:". And in my case ADB is in “C:\Program Files (x86)\Android\android-studio\sdk/platform-tools/adb.exe” and the path is not handled properly. This one looks like an easy fix to me. Or on the other hand… Is CMD or Cygwin supposed to be used by UE normally, for installing the APK?

I am able to manually install the APK on the device. However, when I start it, it only opens up and closes the app. Check the log. [link text][2]

I tested it on UE 4.5 by using a new clean copy of SunTemple and converting it from 4.4 to 4.5. Same problem.

17846-suntemple+build+failed±+ue+log.txt (3.96 KB)
[2]: 17847-suntemple+android+launch+failed±+device+log.txt (4.25 KB)

Would you be using the Launch on feature to deploy to your device or using the package and running the .bat file to deploy to your device?

I used the Launch on feature. Sorry for the delayed response.

Hey,

It’s been quite a while since we have last heard from you. Have you tried this on our newer versions of the engine? We’re currently at 4.8.3 with the 4.9.0 Preview 1 available too.

Thanks!

Hi,

Yes, at some point I was able to build it successfully. Not sure which version it was at that time. I haven’t tried with the latest version but I assume it works (or at least hope so :slight_smile: )

Cheers!

I’m glad that you’ve been able to get passed this issue. If you happen to run into any further issues, please do not hesitate in creating a new thread to AnswerHub!

Have a great day!