Skip to content

Add 2022.3.0 unitypackage #1005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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);
});
");

Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 '<flutter-project>/unity/<unity-project-folder>' .");
Debug.Log($"-- Build: Failed --");
return false;
}
return true;
}

//#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Visit https://github.com/juicycleff/flutter-unity-view-widget

unitypackage version: fuw-2022.2.0
unitypackage version: fuw-2022.3.0
10 changes: 9 additions & 1 deletion unitypackages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added unitypackages/fuw-2022.3.0.unitypackage
Binary file not shown.