diff --git a/example/unity/DemoApp/Assets/FlutterUnityIntegration/Editor/Build.cs b/example/unity/DemoApp/Assets/FlutterUnityIntegration/Editor/Build.cs index 06558f5ee..60ba7a275 100644 --- a/example/unity/DemoApp/Assets/FlutterUnityIntegration/Editor/Build.cs +++ b/example/unity/DemoApp/Assets/FlutterUnityIntegration/Editor/Build.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text.RegularExpressions; using UnityEditor; +using UnityEditor.Build; using UnityEngine; using Application = UnityEngine.Application; using BuildResult = UnityEditor.Build.Reporting.BuildResult; @@ -32,27 +33,18 @@ public class Build : EditorWindow public static void DoBuildAndroidLibraryDebug() { DoBuildAndroid(Path.Combine(APKPath, "unityLibrary"), false, false); - - // Copy over resources from the launcher module that are used by the library - Copy(Path.Combine(APKPath + "/launcher/src/main/res"), Path.Combine(AndroidExportPath, "src/main/res")); } [MenuItem("Flutter/Export Android (Release) %&m", false, 102)] public static void DoBuildAndroidLibraryRelease() { DoBuildAndroid(Path.Combine(APKPath, "unityLibrary"), false, true); - - // Copy over resources from the launcher module that are used by the library - Copy(Path.Combine(APKPath + "/launcher/src/main/res"), Path.Combine(AndroidExportPath, "src/main/res")); } [MenuItem("Flutter/Export Android Plugin %&p", false, 103)] public static void DoBuildAndroidPlugin() { DoBuildAndroid(Path.Combine(APKPath, "unityLibrary"), true, true); - - // Copy over resources from the launcher module that are used by the library - Copy(Path.Combine(APKPath + "/launcher/src/main/res"), Path.Combine(AndroidExportPath, "src/main/res")); } [MenuItem("Flutter/Export IOS (Debug) %&i", false, 201)] @@ -154,6 +146,11 @@ private static void BuildWindowsOS(String path) private static void BuildWebGL(String path) { + // Check if the Unity project is in the expected location + if (!IsProjectLocationValid(path, "web")) { + return; + } + // Switch to Android standalone build. EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android); @@ -187,6 +184,11 @@ private static void BuildWebGL(String path) private static void DoBuildAndroid(String buildPath, bool isPlugin, bool isReleaseBuild) { + // Check if the Unity project is in the expected location + if (!IsProjectLocationValid(AndroidExportPath, "android")) { + return; + } + // Switch to Android standalone build. EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android); @@ -210,10 +212,10 @@ private static void DoBuildAndroid(String buildPath, bool isPlugin, bool isRelea } #if UNITY_2022_1_OR_NEWER PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.Android, isReleaseBuild ? Il2CppCompilerConfiguration.Release : Il2CppCompilerConfiguration.Debug); - PlayerSettings.SetIl2CppCodeGeneration(UnityEditor.Build.NamedBuildTarget.Android, UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize); + PlayerSettings.SetIl2CppCodeGeneration(NamedBuildTarget.Android, isReleaseBuild ? Il2CppCodeGeneration.OptimizeSpeed : Il2CppCodeGeneration.OptimizeSize); #elif UNITY_2021_2_OR_NEWER PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.Android, isReleaseBuild ? Il2CppCompilerConfiguration.Release : Il2CppCompilerConfiguration.Debug); - EditorUserBuildSettings.il2CppCodeGeneration = UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize; + EditorUserBuildSettings.il2CppCodeGeneration = isReleaseBuild ? Il2CppCodeGeneration.OptimizeSpeed : Il2CppCodeGeneration.OptimizeSize; #endif // Switch to Android standalone build. @@ -238,6 +240,9 @@ private static void DoBuildAndroid(String buildPath, bool isPlugin, bool isRelea SetupAndroidProject(); } + // Copy over resources from the launcher module that are used by the library, Avoid deleting the existing src/main/res contents. + Copy(Path.Combine(APKPath + "/launcher/src/main/res"), Path.Combine(AndroidExportPath, "src/main/res"), false); + if (isReleaseBuild) { Debug.Log($"-- Android Release Build: SUCCESSFUL --"); } else @@ -281,7 +286,7 @@ private static void ModifyWebGLExport() }); window.parent.addEventListener('unityFlutterBidingFnCal', function (args) { - mainUnityInstance.SendMessage('GameManager', 'HandleWebFnCall', args); + mainUnityInstance.SendMessage('GameManager', 'HandleWebFnCall', args.data); }); "); @@ -330,7 +335,8 @@ private static void ModifyAndroidGradle(bool isPlugin) buildText = buildText.Replace("enableSplit = true", "enable true"); buildText = buildText.Replace("implementation fileTree(dir: 'libs', include: ['*.jar'])", "implementation(name: 'unity-classes', ext:'jar')"); buildText = buildText.Replace(" + unityStreamingAssets.tokenize(', ')", ""); - buildText = Regex.Replace(buildText, "ndkPath \".*\"", ""); + // disable the Unity ndk path as it will conflict with Flutter. + buildText = buildText.Replace("ndkPath \"", "// ndkPath \""); // check for namespace definition (Android gradle plugin 8+), add a backwards compatible version if it is missing. if(!buildText.Contains("namespace")) @@ -365,6 +371,11 @@ private static void ModifyAndroidGradle(bool isPlugin) private static void BuildIOS(String path, bool isReleaseBuild) { + // Check if the Unity project is in the expected location + if (!IsProjectLocationValid(path, "ios")) { + return; + } + bool abortBuild = false; // abort iOS export if #UNITY_IOS is false. @@ -406,10 +417,10 @@ private static void BuildIOS(String path, bool isReleaseBuild) #if UNITY_2022_1_OR_NEWER PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.iOS, isReleaseBuild ? Il2CppCompilerConfiguration.Release : Il2CppCompilerConfiguration.Debug); - PlayerSettings.SetIl2CppCodeGeneration(UnityEditor.Build.NamedBuildTarget.iOS, UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize); + PlayerSettings.SetIl2CppCodeGeneration(NamedBuildTarget.iOS, isReleaseBuild ? Il2CppCodeGeneration.OptimizeSpeed : Il2CppCodeGeneration.OptimizeSize); #elif UNITY_2021_2_OR_NEWER PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.iOS, isReleaseBuild ? Il2CppCompilerConfiguration.Release : Il2CppCompilerConfiguration.Debug); - EditorUserBuildSettings.il2CppCodeGeneration = UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize; + EditorUserBuildSettings.il2CppCodeGeneration = isReleaseBuild ? Il2CppCodeGeneration.OptimizeSpeed : Il2CppCodeGeneration.OptimizeSize; #endif var playerOptions = new BuildPlayerOptions @@ -458,9 +469,9 @@ private static void BuildIOS(String path, bool isReleaseBuild) //#region Other Member Methods - private static void Copy(string source, string destinationPath) + private static void Copy(string source, string destinationPath, bool clearDestination = true) { - if (Directory.Exists(destinationPath)) + if (clearDestination && Directory.Exists(destinationPath)) Directory.Delete(destinationPath, true); Directory.CreateDirectory(destinationPath); @@ -779,6 +790,21 @@ private static async void BuildUnityFrameworkArchive() } + + // check if the Unity project is in the expected location + private static bool IsProjectLocationValid(string unityLibraryPath, string platform) + { + // android, ios and web use platform/unityLibrary, move up one step. + string platformPath = Path.Combine(unityLibraryPath, "../"); + if (!Directory.Exists(platformPath)) + { + Debug.LogError($"Could not find the Flutter project {platform} folder. Make sure the Unity project folder is located in '/unity/' ."); + Debug.Log($"-- Build: Failed --"); + return false; + } + return true; + } + //#endregion } } diff --git a/example/unity/DemoApp/Assets/FlutterUnityIntegration/README.txt b/example/unity/DemoApp/Assets/FlutterUnityIntegration/README.txt index 553a29594..59a44b58d 100644 --- a/example/unity/DemoApp/Assets/FlutterUnityIntegration/README.txt +++ b/example/unity/DemoApp/Assets/FlutterUnityIntegration/README.txt @@ -2,4 +2,4 @@ Visit https://github.com/juicycleff/flutter-unity-view-widget -unitypackage version: fuw-2022.2.0 \ No newline at end of file +unitypackage version: fuw-2022.3.0 \ No newline at end of file diff --git a/unitypackages/README.md b/unitypackages/README.md index 5597276a5..7c98e1424 100644 --- a/unitypackages/README.md +++ b/unitypackages/README.md @@ -33,8 +33,16 @@ Changes for `2022.1.7f1` and earlier were collected retroactively and might not ## Pending (master branch) > Example Unity project, not in a unitypackage yet. +* *No changes* + +## 2022.3.0 +>fuw-2022.3.0.unitypackage * Avoid invalid iOS export when current build target is not iOS. [#838](https://github.com/juicycleff/flutter-unity-view-widget/pull/838) -* Delete absolute ndk path from Unity export. (Unity 2022.3.x and newer) [#880](https://github.com/juicycleff/flutter-unity-view-widget/pull/880) +* (Android) Disable absolute ndk path from Unity export. (Unity 2022.3.x and newer) +* (Android) Add missing namespace in unityLibrary build.gradle for Android Gradle plugin (AGP) 8.x. +* (Web) Fix Javascript error on Play and Pause. +* (Android) Fix build error `resource style/UnityThemeSelector not found` in the example project. +* Use Il2CppCodeGeneration.OptimizeSpeed in Android and iOS release exports. ## 2022.2.0 diff --git a/unitypackages/fuw-2022.3.0.unitypackage b/unitypackages/fuw-2022.3.0.unitypackage new file mode 100644 index 000000000..4e0231c8c Binary files /dev/null and b/unitypackages/fuw-2022.3.0.unitypackage differ diff --git a/unitypackages/fuw-2022.1.1-v2.unitypackage b/unitypackages/legacy/fuw-2022.1.1-v2.unitypackage similarity index 100% rename from unitypackages/fuw-2022.1.1-v2.unitypackage rename to unitypackages/legacy/fuw-2022.1.1-v2.unitypackage diff --git a/unitypackages/fuw-2022.1.7f1.unitypackage b/unitypackages/legacy/fuw-2022.1.7f1.unitypackage similarity index 100% rename from unitypackages/fuw-2022.1.7f1.unitypackage rename to unitypackages/legacy/fuw-2022.1.7f1.unitypackage