[BUG] If .bash_profile file on OS X has JAVA_HOME environment variable, Android build fails in UE 4.10

anonymous_user_bcd0d281
Thu, 14 Jan 2016 07:26:02 +0000
Debugging, Optimization, & Profiling

I was trying to build an Android APK for Gear VR, and the build process kept failing, stating the following:

MainFrameActions: Packaging (Android (ETC2)): mono: ====1/14/2016 2:13:51 AM====PERFORMING FINAL APK PACKAGE OPERATION================================================
MainFrameActions: Packaging (Android (ETC2)): mono: Making .apk with Ant... (note: it's safe to ignore javac obsolete warnings)
MainFrameActions: Packaging (Android (ETC2)): mono: Error: JAVA_HOME is not defined correctly.
MainFrameActions: Packaging (Android (ETC2)): mono:   We cannot execute $(/System/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home)/bin/java
MainFrameActions: Packaging (Android (ETC2)): mono: UnrealBuildTool Exception: ERROR: /bin/sh failed with args -c '"/Android_TADP//apache-ant-1.8.2/bin/ant" -quiet debug'
MainFrameActions: Packaging (Android (ETC2)): CommandUtils.Run: Run: Took 6.428365s to run mono, ExitCode=5
MainFrameActions: Packaging (Android (ETC2)): BuildCommand.Execute: ERROR: BUILD FAILED
MainFrameActions: Packaging (Android (ETC2)): Program.Main: ERROR: AutomationTool terminated with exception:
MainFrameActions: Packaging (Android (ETC2)): Program.Main: ERROR: Exception in AutomationUtils.Automation: Command failed (Result:5): /Users/Shared/UnrealEngine/4.10/Engine/Binaries/DotNET/UnrealBuildTool.exe "/Users/jonathandaley/Documents/Unreal Projects/VRNavTutorial/VRNavTutorial.uproject" Android Development -prepfordeploy -rocket -nocreatestub -NoHotReloadFromIDE -ignorejunk. See logfile for details: 'UnrealBuildTool-2016.01.14-02.13.44.txt'
MainFrameActions: Packaging (Android (ETC2)): Stacktrace:   at AutomationTool.CommandUtils.RunAndLog (System.String App, System.String CommandLine, System.String Logfile, Int32 MaxSuccessCode, System.String Input, ERunOptions Options, System.Collections.Generic.Dictionary`2 EnvVars) [0x00000] in <filename unknown>:0
MainFrameActions: Packaging (Android (ETC2)):   at AutomationTool.CommandUtils.RunAndLog (AutomationTool.CommandEnvironment Env, System.String App, System.String CommandLine, System.String LogName, Int32 MaxSuccessCode, System.String Input, ERunOptions Options, System.Collections.Generic.Dictionary`2 EnvVars) [0x00000] in <filename unknown>:0
MainFrameActions: Packaging (Android (ETC2)):   at AutomationTool.CommandUtils.RunUBT (AutomationTool.CommandEnvironment Env, System.String UBTExecutable, System.String CommandLine, System.String LogName, System.Collections.Generic.Dictionary`2 EnvVars) [0x00000] in <filename unknown>:0
MainFrameActions: Packaging (Android (ETC2)):   at AndroidPlatform.PostBuildTarget (AutomationTool.UE4Build Build, System.String ProjectName, System.String UProjectPath, System.String Config) [0x00000] in <filename unknown>:0
MainFrameActions: Packaging (Android (ETC2)):   at AutomationTool.UE4Build.BuildWithUBT (System.String ProjectName, System.String TargetName, UnrealTargetPlatform TargetPlatform, System.String Config, System.String UprojectPath, Boolean ForceMonolithic, Boolean ForceNonUnity, Boolean ForceDebugInfo, Boolean ForceFlushMac, Boolean DisableXGE, System.String InAddArgs, Boolean ForceUnity, System.Collections.Generic.Dictionary`2 EnvVars) [0x00000] in <filename unknown>:0
MainFrameActions: Packaging (Android (ETC2)):   at AutomationTool.UE4Build.Build (AutomationTool.BuildAgenda Agenda, Nullable`1 InDeleteBuildProducts, Boolean InUpdateVersionFiles, Boolean InForceNoXGE, Boolean InUseParallelExecutor, Boolean InForceNonUnity, Boo
MainFrameActions: Packaging (Android (ETC2)): lean InForceUnity, Boolean InShowProgress, System.Collections.Generic.Dictionary`2 PlatformEnvVars) [0x00000] in <filename unknown>:0
MainFrameActions: Packaging (Android (ETC2)):   at Project.Build (BuildCommand Command, AutomationTool.ProjectParams Params, Int32 WorkingCL) [0x00000] in <filename unknown>:0
MainFrameActions: Packaging (Android (ETC2)):   at BuildCookRun.DoBuildCookRun (AutomationTool.ProjectParams Params) [0x00000] in <filename unknown>:0
MainFrameActions: Packaging (Android (ETC2)):   at BuildCookRun.ExecuteBuild () [0x00000] in <filename unknown>:0
MainFrameActions: Packaging (Android (ETC2)):   at BuildCommand.Execute () [0x00000] in <filename unknown>:0
MainFrameActions: Packaging (Android (ETC2)): Program.Main: AutomationTool exiting with ExitCode=5
MainFrameActions: Packaging (Android (ETC2)): Domain_ProcessExit
MainFrameActions: Packaging (Android (ETC2)): RunUAT ERROR: AutomationTool was unable to run successfully.
PackagingResults:Error: Error Unknown Error

The key part being:

    MainFrameActions: Packaging (Android (ETC2)): mono: Error: JAVA_HOME is not defined correctly.
    MainFrameActions: Packaging (Android (ETC2)): mono:   We cannot execute $(/System/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home)/bin/java
    MainFrameActions: Packaging (Android (ETC2)): mono: UnrealBuildTool Exception: ERROR: /bin/sh failed with args -c '"/Android_TADP//apache-ant-1.8.2/bin/ant" -quiet debug'

After much searching on the AnswerHub, and lots of tinkering, it turns out that if you have a JAVA_HOME environment variable in the .bash_profile file on OS X, the Android build will fail. When I commented out that environment variable, it built just fine.

3 posts - 1 participant