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:
During the installation of the Unity Editor, make sure to include the Android Build Support module by checking the box next to it. Expand the Android Build Support module. If you are using Unity 2019 or later, add the Android SDK & NDK Tools module. On the Projects tab, click New to start a new Unity project.
Go to the Unity Editor. From the menu, choose 'File', 'Build Settings…' In the Build Settings dialog, under 'Platform', select 'Android' as the target and click 'Switch Platform'.
Whether you're building an Android application in Unity or programming it from scratch, you need to set up the Android SDK (software development kit) before you can build and run any code on your Android device.
To build and run for Android, you must install the Unity Android Build Support platform module. You also need to install the Android Software Development Kit (SDK) and the Native Development Kit (NDK) to build and run any code on your Android device. By default, Unity installs a Java Development Kit based on OpenJDK.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With