Skip to content

Commit

Permalink
Update build.cs for Unity 6000.
Browse files Browse the repository at this point in the history
  • Loading branch information
timbotimbo committed Jul 2, 2024
1 parent 56e7530 commit 6d0e4b2
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,22 @@ private static void DoBuildAndroid(String buildPath, bool isPlugin, bool isRelea
// remove this line if you don't use a debugger and you want to speed up the flutter build
playerOptions.options = BuildOptions.AllowDebugging | BuildOptions.Development;
}
#if UNITY_2022_1_OR_NEWER
#if UNITY_6000_0_OR_NEWER
PlayerSettings.SetIl2CppCompilerConfiguration(UnityEditor.Build.NamedBuildTarget.Android, isReleaseBuild ? Il2CppCompilerConfiguration.Release : Il2CppCompilerConfiguration.Debug);
PlayerSettings.SetIl2CppCodeGeneration(UnityEditor.Build.NamedBuildTarget.Android, UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize);
#elif UNITY_2022_1_OR_NEWER
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.Android, isReleaseBuild ? Il2CppCompilerConfiguration.Release : Il2CppCompilerConfiguration.Debug);
PlayerSettings.SetIl2CppCodeGeneration(UnityEditor.Build.NamedBuildTarget.Android, UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize);
#elif UNITY_2021_2_OR_NEWER
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.Android, isReleaseBuild ? Il2CppCompilerConfiguration.Release : Il2CppCompilerConfiguration.Debug);
EditorUserBuildSettings.il2CppCodeGeneration = UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize;
#endif


#if UNITY_ANDROID && UNITY_6000_0_OR_NEWER
UnityEditor.Android.UserBuildSettings.DebugSymbols.level = isReleaseBuild ? Unity.Android.Types.DebugSymbolLevel.None : Unity.Android.Types.DebugSymbolLevel.SymbolTable;
UnityEditor.Android.UserBuildSettings.DebugSymbols.format = Unity.Android.Types.DebugSymbolFormat.LegacyExtensions;
#endif
// Switch to Android standalone build.
EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android);
// build addressable
Expand All @@ -227,6 +235,13 @@ private static void DoBuildAndroid(String buildPath, bool isPlugin, bool isRelea

Copy(buildPath, AndroidExportPath);

// Unity 6000 shared folder
string sharedPath = Path.Combine(APKPath, "shared");
if (Directory.Exists(sharedPath))
{
Copy(sharedPath, Path.Combine(AndroidExportPath, "shared"));
}

// Modify build.gradle
ModifyAndroidGradle(isPlugin);

Expand Down Expand Up @@ -332,6 +347,10 @@ private static void ModifyAndroidGradle(bool isPlugin)
buildText = buildText.Replace(" + unityStreamingAssets.tokenize(', ')", "");
buildText = Regex.Replace(buildText, "ndkPath \".*\"", "");

// Untiy 6000, handle ../shared/
buildText = Regex.Replace(buildText, @"\.\./shared/", "./shared/");


// check for namespace definition (Android gradle plugin 8+), add a backwards compatible version if it is missing.
if(!buildText.Contains("namespace"))
{
Expand Down Expand Up @@ -404,7 +423,10 @@ private static void BuildIOS(String path, bool isReleaseBuild)
EditorUserBuildSettings.iOSBuildConfigType = iOSBuildType.Release;
#endif

#if UNITY_2022_1_OR_NEWER
#if UNITY_6000_0_OR_NEWER
PlayerSettings.SetIl2CppCompilerConfiguration(UnityEditor.Build.NamedBuildTarget.Android, isReleaseBuild ? Il2CppCompilerConfiguration.Release : Il2CppCompilerConfiguration.Debug);
PlayerSettings.SetIl2CppCodeGeneration(UnityEditor.Build.NamedBuildTarget.Android, UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize);
#elif UNITY_2022_1_OR_NEWER
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.iOS, isReleaseBuild ? Il2CppCompilerConfiguration.Release : Il2CppCompilerConfiguration.Debug);
PlayerSettings.SetIl2CppCodeGeneration(UnityEditor.Build.NamedBuildTarget.iOS, UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize);
#elif UNITY_2021_2_OR_NEWER
Expand Down

0 comments on commit 6d0e4b2

Please sign in to comment.