Skip to content

Commit 1b35b3a

Browse files
committed
Merge branch 'master' into experimental/unity_6000
2 parents fef61dc + c8b112e commit 1b35b3a

File tree

6 files changed

+53
-19
lines changed

6 files changed

+53
-19
lines changed

example/unity/DemoApp/Assets/FlutterUnityIntegration/Editor/Build.cs

+43-17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Text.RegularExpressions;
55
using UnityEditor;
6+
using UnityEditor.Build;
67
using UnityEngine;
78
using Application = UnityEngine.Application;
89
using BuildResult = UnityEditor.Build.Reporting.BuildResult;
@@ -32,27 +33,18 @@ public class Build : EditorWindow
3233
public static void DoBuildAndroidLibraryDebug()
3334
{
3435
DoBuildAndroid(Path.Combine(APKPath, "unityLibrary"), false, false);
35-
36-
// Copy over resources from the launcher module that are used by the library
37-
Copy(Path.Combine(APKPath + "/launcher/src/main/res"), Path.Combine(AndroidExportPath, "src/main/res"));
3836
}
3937

4038
[MenuItem("Flutter/Export Android (Release) %&m", false, 102)]
4139
public static void DoBuildAndroidLibraryRelease()
4240
{
4341
DoBuildAndroid(Path.Combine(APKPath, "unityLibrary"), false, true);
44-
45-
// Copy over resources from the launcher module that are used by the library
46-
Copy(Path.Combine(APKPath + "/launcher/src/main/res"), Path.Combine(AndroidExportPath, "src/main/res"));
4742
}
4843

4944
[MenuItem("Flutter/Export Android Plugin %&p", false, 103)]
5045
public static void DoBuildAndroidPlugin()
5146
{
5247
DoBuildAndroid(Path.Combine(APKPath, "unityLibrary"), true, true);
53-
54-
// Copy over resources from the launcher module that are used by the library
55-
Copy(Path.Combine(APKPath + "/launcher/src/main/res"), Path.Combine(AndroidExportPath, "src/main/res"));
5648
}
5749

5850
[MenuItem("Flutter/Export IOS (Debug) %&i", false, 201)]
@@ -154,6 +146,11 @@ private static void BuildWindowsOS(String path)
154146

155147
private static void BuildWebGL(String path)
156148
{
149+
// Check if the Unity project is in the expected location
150+
if (!IsProjectLocationValid(path, "web")) {
151+
return;
152+
}
153+
157154
// Switch to Android standalone build.
158155
EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android);
159156

@@ -187,6 +184,11 @@ private static void BuildWebGL(String path)
187184

188185
private static void DoBuildAndroid(String buildPath, bool isPlugin, bool isReleaseBuild)
189186
{
187+
// Check if the Unity project is in the expected location
188+
if (!IsProjectLocationValid(AndroidExportPath, "android")) {
189+
return;
190+
}
191+
190192
// Switch to Android standalone build.
191193
EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android);
192194

@@ -213,10 +215,10 @@ private static void DoBuildAndroid(String buildPath, bool isPlugin, bool isRelea
213215
PlayerSettings.SetIl2CppCodeGeneration(UnityEditor.Build.NamedBuildTarget.Android, UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize);
214216
#elif UNITY_2022_1_OR_NEWER
215217
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.Android, isReleaseBuild ? Il2CppCompilerConfiguration.Release : Il2CppCompilerConfiguration.Debug);
216-
PlayerSettings.SetIl2CppCodeGeneration(UnityEditor.Build.NamedBuildTarget.Android, UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize);
218+
PlayerSettings.SetIl2CppCodeGeneration(NamedBuildTarget.Android, isReleaseBuild ? Il2CppCodeGeneration.OptimizeSpeed : Il2CppCodeGeneration.OptimizeSize);
217219
#elif UNITY_2021_2_OR_NEWER
218220
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.Android, isReleaseBuild ? Il2CppCompilerConfiguration.Release : Il2CppCompilerConfiguration.Debug);
219-
EditorUserBuildSettings.il2CppCodeGeneration = UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize;
221+
EditorUserBuildSettings.il2CppCodeGeneration = isReleaseBuild ? Il2CppCodeGeneration.OptimizeSpeed : Il2CppCodeGeneration.OptimizeSize;
220222
#endif
221223

222224

@@ -256,6 +258,9 @@ private static void DoBuildAndroid(String buildPath, bool isPlugin, bool isRelea
256258
SetupAndroidProject();
257259
}
258260

261+
// Copy over resources from the launcher module that are used by the library, Avoid deleting the existing src/main/res contents.
262+
Copy(Path.Combine(APKPath + "/launcher/src/main/res"), Path.Combine(AndroidExportPath, "src/main/res"), false);
263+
259264
if (isReleaseBuild) {
260265
Debug.Log($"-- Android Release Build: SUCCESSFUL --");
261266
} else
@@ -299,7 +304,7 @@ private static void ModifyWebGLExport()
299304
});
300305
301306
window.parent.addEventListener('unityFlutterBidingFnCal', function (args) {
302-
mainUnityInstance.SendMessage('GameManager', 'HandleWebFnCall', args);
307+
mainUnityInstance.SendMessage('GameManager', 'HandleWebFnCall', args.data);
303308
});
304309
");
305310

@@ -348,7 +353,8 @@ private static void ModifyAndroidGradle(bool isPlugin)
348353
buildText = buildText.Replace("enableSplit = true", "enable true");
349354
buildText = buildText.Replace("implementation fileTree(dir: 'libs', include: ['*.jar'])", "implementation(name: 'unity-classes', ext:'jar')");
350355
buildText = buildText.Replace(" + unityStreamingAssets.tokenize(', ')", "");
351-
buildText = Regex.Replace(buildText, "ndkPath \".*\"", "");
356+
// disable the Unity ndk path as it will conflict with Flutter.
357+
buildText = buildText.Replace("ndkPath \"", "// ndkPath \"");
352358

353359
// Untiy 6000, handle ../shared/
354360
buildText = Regex.Replace(buildText, @"\.\./shared/", "./shared/");
@@ -387,6 +393,11 @@ private static void ModifyAndroidGradle(bool isPlugin)
387393

388394
private static void BuildIOS(String path, bool isReleaseBuild)
389395
{
396+
// Check if the Unity project is in the expected location
397+
if (!IsProjectLocationValid(path, "ios")) {
398+
return;
399+
}
400+
390401
bool abortBuild = false;
391402

392403
// abort iOS export if #UNITY_IOS is false.
@@ -431,10 +442,10 @@ private static void BuildIOS(String path, bool isReleaseBuild)
431442
PlayerSettings.SetIl2CppCodeGeneration(UnityEditor.Build.NamedBuildTarget.Android, UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize);
432443
#elif UNITY_2022_1_OR_NEWER
433444
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.iOS, isReleaseBuild ? Il2CppCompilerConfiguration.Release : Il2CppCompilerConfiguration.Debug);
434-
PlayerSettings.SetIl2CppCodeGeneration(UnityEditor.Build.NamedBuildTarget.iOS, UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize);
445+
PlayerSettings.SetIl2CppCodeGeneration(NamedBuildTarget.iOS, isReleaseBuild ? Il2CppCodeGeneration.OptimizeSpeed : Il2CppCodeGeneration.OptimizeSize);
435446
#elif UNITY_2021_2_OR_NEWER
436447
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.iOS, isReleaseBuild ? Il2CppCompilerConfiguration.Release : Il2CppCompilerConfiguration.Debug);
437-
EditorUserBuildSettings.il2CppCodeGeneration = UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize;
448+
EditorUserBuildSettings.il2CppCodeGeneration = isReleaseBuild ? Il2CppCodeGeneration.OptimizeSpeed : Il2CppCodeGeneration.OptimizeSize;
438449
#endif
439450

440451
var playerOptions = new BuildPlayerOptions
@@ -483,9 +494,9 @@ private static void BuildIOS(String path, bool isReleaseBuild)
483494

484495

485496
//#region Other Member Methods
486-
private static void Copy(string source, string destinationPath)
497+
private static void Copy(string source, string destinationPath, bool clearDestination = true)
487498
{
488-
if (Directory.Exists(destinationPath))
499+
if (clearDestination && Directory.Exists(destinationPath))
489500
Directory.Delete(destinationPath, true);
490501

491502
Directory.CreateDirectory(destinationPath);
@@ -804,6 +815,21 @@ private static async void BuildUnityFrameworkArchive()
804815

805816
}
806817

818+
819+
// check if the Unity project is in the expected location
820+
private static bool IsProjectLocationValid(string unityLibraryPath, string platform)
821+
{
822+
// android, ios and web use platform/unityLibrary, move up one step.
823+
string platformPath = Path.Combine(unityLibraryPath, "../");
824+
if (!Directory.Exists(platformPath))
825+
{
826+
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>' .");
827+
Debug.Log($"-- Build: Failed --");
828+
return false;
829+
}
830+
return true;
831+
}
832+
807833
//#endregion
808834
}
809835
}

example/unity/DemoApp/Assets/FlutterUnityIntegration/README.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

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

5-
unitypackage version: fuw-2022.2.0
5+
unitypackage version: fuw-2022.3.0

unitypackages/README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,16 @@ Changes for `2022.1.7f1` and earlier were collected retroactively and might not
3333

3434
## Pending (master branch)
3535
> Example Unity project, not in a unitypackage yet.
36+
* *No changes*
37+
38+
## 2022.3.0
39+
>fuw-2022.3.0.unitypackage
3640
* Avoid invalid iOS export when current build target is not iOS. [#838](https://github.com/juicycleff/flutter-unity-view-widget/pull/838)
37-
* Delete absolute ndk path from Unity export. (Unity 2022.3.x and newer) [#880](https://github.com/juicycleff/flutter-unity-view-widget/pull/880)
41+
* (Android) Disable absolute ndk path from Unity export. (Unity 2022.3.x and newer)
42+
* (Android) Add missing namespace in unityLibrary build.gradle for Android Gradle plugin (AGP) 8.x.
43+
* (Web) Fix Javascript error on Play and Pause.
44+
* (Android) Fix build error `resource style/UnityThemeSelector not found` in the example project.
45+
* Use Il2CppCodeGeneration.OptimizeSpeed in Android and iOS release exports.
3846

3947

4048
## 2022.2.0
612 KB
Binary file not shown.

0 commit comments

Comments
 (0)