如何将Unity 2017.4配置为以Android为目标并避免在OSX上构建失败? [英] How to configure Unity 2017.4 to target Android and avoid build failures on OSX?

查看:133
本文介绍了如何将Unity 2017.4配置为以Android为目标并避免在OSX上构建失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在安装带有最新版本的Android Studio(3.1)和Unity(2017.4)的全新/新系统后,我一直在努力解决多个构建失败的问题.诸如以下错误: CommandInvokationFailure:无法列出目标平台.请确保跨多个重复项的android sdk路径正确,因为提供的解决方案是解决方法,并且不能很好地解释根本问题以及如何在Mac上正常解决此问题.

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.

Unity-> Preferences-> External中 工具:我已经正确设置了Android SDK路径,使其指向由Android Studio安装的路径,也已将JDK设置为指向JDK 8版本(我知道现在Android工具无法与Java 9+一起使用)但我仍然遇到构建失败.

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. 允许我保留多个Java版本(我使用 jenv )
  2. 在我的Java设置中不会弄乱符号链接
  3. 允许我使用我的android sdk安装(我在Android Studio中使用一个),并且不需要我搞乱它(例如,降级Android Tools),除非通过正式安装任何缺少的模块

推荐答案

看来,Android为了构建当前版本的Unity,不仅依赖于 Preferences-> External Tools ,也可以在Mac上由命令/usr/libexec/java_home返回的全局Java主目录上.因此,两者都必须指向JDK 8版本(v 9或10无效).

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

因此,如果您不是从系统中删除Java 9/10的选项,则必须确保/usr/libexec/java_home指向JDK 8安装.

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.

不幸的是,此命令不允许您设置或配置特定的JDK-默认情况下,它会根据对每个VM中ContentsInfo.plist中提供的信息进行排序,返回最高版本.

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.

先决条件:确保已通过Android Studio的SDK管理器下载了构建所需的所有模块

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

解决方案:要正常解决此问题,您可以转到/Library/Java/JavaVirtualMachines,找到等于或大于9(现在为9或10)的VM,并在其Contents目录中重命名Info.plistInfo.plist.off或类似.当$JAVA_HOME指向JDK时仍可以使用该JDK,或者可以在脚本或配置中明确引用该JDK(例如,与jenv一起使用).完成此操作后,/usr/libexec/java_home将指向JDK 8 VM,并且构建将成功.

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.

希望如此,一旦Google确保Android工具能够与最新版本的Java配合使用,并且Unity完全依赖于已配置的SDK,而不是任意使用系统范围/全局Java系统,这将不是问题.

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.

这篇关于如何将Unity 2017.4配置为以Android为目标并避免在OSX上构建失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆