Created
December 21, 2023 04:05
-
-
Save dyguests/8f89f0658a26f1bbd73c97e16b89440c to your computer and use it in GitHub Desktop.
Unity set Android JAVA_HOME
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEditor.Build; | |
using UnityEditor.Build.Reporting; | |
public class CustomAndroidPreprocessBuild : IPreprocessBuildWithReport | |
{ | |
public int callbackOrder => 0; | |
public void OnPreprocessBuild(BuildReport report) | |
{ | |
// Win设置环境变量: 略 | |
// Mac设置bash能用的环境变量: 略 | |
// Mac设置从应用启动图标启动时也能访问到的环境变量: https://stackoverflow.com/a/26586170/4072786 | |
var unityJavaHome = Environment.GetEnvironmentVariable("JAVA_HOME"); | |
var androidJavaHome = Environment.GetEnvironmentVariable("ANDROID_JAVA_HOME"); | |
Environment.SetEnvironmentVariable("JAVA_HOME", androidJavaHome); | |
// TODO android process | |
Environment.SetEnvironmentVariable("JAVA_HOME", unityJavaHome); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment