Skip to content

Commit 351859f

Browse files
Rename the IOSResolver DLL on import in order to resolve a bug in Unity 2021
googlesamples/unity-jar-resolver#441
1 parent f29b57b commit 351859f

File tree

1 file changed

+38
-18
lines changed

1 file changed

+38
-18
lines changed
Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
11
using System.IO;
2+
using System.Linq;
23
using UnityEditor;
34
using UnityEditor.Compilation;
45
using UnityEngine;
56

67
/// <summary>
78
/// Checks for EDM4U assemblies and installs the package from its github releases
89
/// </summary>
9-
public sealed class InstallEdm4uStep : OneSignalSetupStep
10+
public sealed class InstallEdm4uStep : OneSignalSetupStep
1011
{
1112
public override string Summary
1213
=> $"Install EDM4U {_edm4UVersion}";
1314

1415
public override string Details
1516
=> $"Downloads and imports version {_edm4UVersion} from Google's repo. This library resolves dependencies " +
16-
$"among included libraries on Android.";
17+
#if UNITY_2021_1_OR_NEWER
18+
"among included libraries on Android.\n\n<b>NOTE</b>: In Unity 2021+ the " +
19+
$"Google.IOSResolver_v{_edm4UVersion}.dll will be renamed to Google.IOSResolver.dll in order to resolve a bug.";
20+
#else
21+
"among included libraries on Android.";
22+
#endif
1723

18-
public override bool IsRequired
24+
public override bool IsRequired
1925
=> true;
2026

2127
protected override bool _getIsStepCompleted()
22-
{
23-
var precompiledAssemblies = CompilationPipeline.GetPrecompiledAssemblyNames();
24-
foreach (var assemblyName in precompiledAssemblies)
25-
{
26-
if (assemblyName.StartsWith("Google.VersionHandler"))
27-
return true;
28-
}
29-
30-
return false;
31-
}
28+
=> CompilationPipeline.GetPrecompiledAssemblyNames()
29+
.Any(assemblyName => assemblyName.StartsWith("Google.VersionHandler"));
3230

33-
protected override void _runStep()
31+
protected override void _runStep()
3432
{
3533
var request = EditorWebRequest.Get(_edm4UPackageDownloadUrl);
3634
request.AddEditorProgressDialog("Downloading Google External Dependency Manager");
37-
request.Send(unityRequest =>
35+
request.Send(unityRequest =>
3836
{
39-
if (unityRequest.error != null)
37+
if (unityRequest.error != null)
4038
{
4139
EditorUtility.DisplayDialog("Package Download failed.", unityRequest.error, "Ok");
4240
return;
@@ -47,13 +45,35 @@ protected override void _runStep()
4745
var tmpPackageFile = projectPath + FileUtil.GetUniqueTempPathInProject() + ".unityPackage";
4846

4947
File.WriteAllBytes(tmpPackageFile, unityRequest.downloadHandler.data);
50-
5148
AssetDatabase.ImportPackage(tmpPackageFile, false);
49+
50+
#if UNITY_2021_1_OR_NEWER
51+
SessionState.SetBool(_shouldFix2021Bug, true);
52+
#endif
53+
5254
_shouldCheckForCompletion = true;
5355
});
5456
}
57+
58+
[InitializeOnLoadMethod]
59+
public static void _fixUnity2021Bug()
60+
{
61+
if (!SessionState.GetBool(_shouldFix2021Bug, false))
62+
return;
63+
64+
SessionState.EraseBool(_shouldFix2021Bug);
65+
66+
EditorApplication.delayCall += () => {
67+
File.Move(_iosDLLSourcePath, _iosDLLDestPath);
68+
File.Move(_iosDLLSourcePath + ".meta", _iosDLLDestPath + ".meta");
69+
};
70+
}
5571

5672
private const string _edm4UVersion = "1.2.165";
73+
private const string _shouldFix2021Bug = "onesignal.installedm4u.shouldfix2021bug";
74+
private const string _iosDLLDestPath = "Assets/ExternalDependencyManager/Editor/Google.IOSResolver.dll";
75+
private static readonly string _iosDLLSourcePath = $"Assets/ExternalDependencyManager/Editor/Google.IOSResolver_v{_edm4UVersion}.dll";
5776

58-
static readonly string _edm4UPackageDownloadUrl = $"https://github.com/googlesamples/unity-jar-resolver/blob/v{_edm4UVersion}/external-dependency-manager-{_edm4UVersion}.unitypackage?raw=true";
77+
static readonly string _edm4UPackageDownloadUrl
78+
= $"https://github.com/googlesamples/unity-jar-resolver/blob/v{_edm4UVersion}/external-dependency-manager-{_edm4UVersion}.unitypackage?raw=true";
5979
}

0 commit comments

Comments
 (0)