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

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

问题描述

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

Unity -> 首选项 -> 外部工具 我已正确设置 Android SDK 路径以指向 Android Studio 安装的路径,并将 JDK 设置为指向 JDK 8 版本(我知道现在 Android 工具不适用于 Java 9+)但我仍然遇到构建失败.

我正在寻找一种解决方案:

  1. 允许我保留多个 Java 版本(我使用 jenv)
  2. 不会在我的 Java 设置中弄乱符号链接
  3. 允许我使用我的 android sdk 安装(我在 Android Studio 中使用)并且不需要我去搞乱它(例如降级 Android 工具),除非正式安装任何丢失的模块

解决方案

看来,为了做Android构建当前版本的Unity不仅仅依赖于Preferences -> External Tools中设置的JDK 以及 Mac 上命令 /usr/libexec/java_home 返回的全局 java 主目录.所以两者都必须指向 JDK 8 版本(v 9 或 10 将不起作用).

因此,如果您无法从系统中删除 Java 9/10,则必须确保 /usr/libexec/java_home 指向 JDK 8 安装.>

不幸的是,此命令不允许您设置或配置特定的 JDK - 它默认返回最高版本,基于对 Info.plistContents 中提供的信息进行排序代码>在每个虚拟机中.

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

解决方案:为了优雅地解决这个问题,您可以转到 /Library/Java/JavaVirtualMachines,找到等于 9 或更大(现在是 9 或10) 并在他们的 Contents 目录中将 Info.plist 重命名为 Info.plist.off 或类似名称.当 $JAVA_HOME 指向它时,该 JDK 仍然可以使用,或者在脚本或配置中显式引用(例如与 jenv 一起使用).执行此操作后,/usr/libexec/java_home 将指向 JDK 8 VM,您的构建将成功.

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

>

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

解决方案

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.

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

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