How to configure Unity 2017.4 to target Android and avoid build failures on OSX?

German :

I have been struggling with several build failures after installing a fresh/new system with the latest version of Android Studio (3.1) and Unity (2017.4). Failures like: CommandInvokationFailure: Unable to list target platforms. Please make sure the android sdk path is correct that span multiple duplicates since offered solutions are workarounds and do not explain the root problem well and how to gracefully solve this on Mac.

In Unity -> Preferences -> External Tools I have properly set the Android SDK path to point to the one installed by Android Studio and also the JDK to point to a JDK 8 version (I know that right now the Android tools do not work with Java 9+) but I still get the build failures.

I'm looking for a solution that:

  1. allows me to keep multiple java versions (I use jenv)
  2. does not mess with symlinks in my java setup
  3. allows me to use my android sdk installation (I use the one in Android Studio) and does not require me to mess with it (e.g downgrading Android Tools) except by officially installing any missing module
German :

It seems that in order to do the Android builds the current version of Unity not only relies on the JDK set up in Preferences -> External Tools but also on the global java home as returned by the command /usr/libexec/java_home on Macs. So both must point to a JDK 8 version (v 9 or 10 won't work).

So, if it's not an option for you to remove Java 9/10 from the system, you will have to make sure /usr/libexec/java_home points to the JDK 8 installation.

Unfortunately this command does not allow you to set or configure a specific JDK - it returns the highest version by default, based on sorting the info provided in Info.plist under Contents in each VM.

Prerequisite: make sure you have downloaded all necessary modules for your build via Android Studio's SDK manager

Solution: In order to fix this gracefully you can go to /Library/Java/JavaVirtualMachines, locate the VMs equal to 9 or greater (right now either 9 or 10) and in their Contents directory rename Info.plist to Info.plist.off or similar. That JDK can still be used when $JAVA_HOME points to it, or is explicitly referenced in a script or configuration (e.g. used with jenv). After you do this /usr/libexec/java_home will point to a JDK 8 VM and your build will succeed.

Hopefully this will be a non issue once Google makes sure the Android tools work with the latest versions of Java, and once Unity relies completely on the configured SDK instead of also using the system-wide/global Java system arbitrarily.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=459143&siteId=1