@@ -383,8 +383,22 @@ public void Poll(Func<T> getCurrentValue, Changed changed) {
383
383
384
384
/// <summary>
385
385
/// Resolver that uses Gradle to download libraries and embed them within a Unity project.
386
+ /// Lazy initialize it only when current build target is Android.
386
387
/// </summary>
387
- private static GradleResolver gradleResolver ;
388
+ private static GradleResolver GradleResolverInstance {
389
+ get {
390
+ if ( gradleResolverInstance == null &&
391
+ EditorUserBuildSettings . activeBuildTarget == BuildTarget . Android ) {
392
+ gradleResolverInstance = new GradleResolver ( ) ;
393
+ }
394
+ return gradleResolverInstance ;
395
+ }
396
+ }
397
+
398
+ /// <summary>
399
+ /// Instance of GradleResolver.
400
+ /// </summary>
401
+ private static GradleResolver gradleResolverInstance = null ;
388
402
389
403
/// <summary>
390
404
/// Resoluton job.
@@ -954,8 +968,6 @@ private static bool Initialize() {
954
968
"please report to the developer." ) ;
955
969
}
956
970
957
- // Create the resolver.
958
- gradleResolver = new GradleResolver ( ) ;
959
971
// Monitor Android dependency XML files to perform auto-resolution.
960
972
AddAutoResolutionFilePatterns ( xmlDependencies . fileRegularExpressions ) ;
961
973
@@ -1091,7 +1103,7 @@ private static void OnPostprocessAllAssets(string[] importedAssets,
1091
1103
string [ ] deletedAssets ,
1092
1104
string [ ] movedAssets ,
1093
1105
string [ ] movedFromAssetPaths ) {
1094
- if ( gradleResolver != null ) {
1106
+ if ( GradleResolverInstance != null ) {
1095
1107
// If the manifest changed, try patching it.
1096
1108
var manifestPath = FileUtils . NormalizePathSeparators (
1097
1109
SettingsDialogObj . AndroidManifestPath ) ;
@@ -1150,7 +1162,7 @@ private static void OnPostProcessScene() {
1150
1162
if ( UnityEngine . Application . isPlaying ) return ;
1151
1163
// If the Android resolver isn't enabled or automatic resolution is disabled,
1152
1164
// do nothing.
1153
- if ( gradleResolver == null || ! SettingsDialogObj . AutoResolveOnBuild ) {
1165
+ if ( GradleResolverInstance == null || ! SettingsDialogObj . AutoResolveOnBuild ) {
1154
1166
return ;
1155
1167
}
1156
1168
// If post-processing has already been executed since this module was loaded, don't
@@ -1231,7 +1243,7 @@ private static void AutoResolve(Action resolutionComplete) {
1231
1243
/// Auto-resolve if any packages need to be resolved.
1232
1244
/// </summary>
1233
1245
private static void Reresolve ( ) {
1234
- if ( AutomaticResolutionEnabled && gradleResolver != null ) {
1246
+ if ( AutomaticResolutionEnabled && GradleResolverInstance != null ) {
1235
1247
ScheduleAutoResolve ( ) ;
1236
1248
}
1237
1249
}
@@ -1940,15 +1952,23 @@ private static void ResolveUnsafe(Action<bool> resolutionComplete,
1940
1952
} ) ;
1941
1953
} else {
1942
1954
lastError = "" ;
1943
- gradleResolver . DoResolution (
1944
- SettingsDialogObj . PackageDir ,
1945
- closeWindowOnCompletion ,
1946
- ( ) => {
1947
- RunOnMainThread . Run ( ( ) => {
1948
- finishResolution ( String . IsNullOrEmpty ( lastError ) &&
1949
- patchGradleProperties ( ) , lastError ) ;
1950
- } ) ;
1955
+ if ( GradleResolverInstance != null ) {
1956
+ GradleResolverInstance . DoResolution (
1957
+ SettingsDialogObj . PackageDir ,
1958
+ closeWindowOnCompletion ,
1959
+ ( ) => {
1960
+ RunOnMainThread . Run ( ( ) => {
1961
+ finishResolution ( String . IsNullOrEmpty ( lastError ) &&
1962
+ patchGradleProperties ( ) , lastError ) ;
1963
+ } ) ;
1964
+ } ) ;
1965
+ } else {
1966
+ // Fail the resolution if gradleResolver is not initialized.
1967
+ RunOnMainThread . Run ( ( ) => {
1968
+ finishResolution ( false , "GradleResolver is not created. Is your " +
1969
+ "current build target set to Android?" ) ;
1951
1970
} ) ;
1971
+ }
1952
1972
}
1953
1973
}
1954
1974
@@ -1986,7 +2006,7 @@ public static void SettingsDialog()
1986
2006
/// Interactive resolution of dependencies.
1987
2007
/// </summary>
1988
2008
private static void ExecuteMenuResolve ( bool forceResolution ) {
1989
- if ( gradleResolver == null ) {
2009
+ if ( GradleResolverInstance == null ) {
1990
2010
NotAvailableDialog ( ) ;
1991
2011
return ;
1992
2012
}
@@ -2428,7 +2448,7 @@ internal static void DeleteLabeledAssets() {
2428
2448
internal static void OnSettingsChanged ( ) {
2429
2449
PlayServicesSupport . verboseLogging = SettingsDialogObj . VerboseLogging ;
2430
2450
logger . Verbose = SettingsDialogObj . VerboseLogging ;
2431
- if ( gradleResolver != null ) {
2451
+ if ( GradleResolverInstance != null ) {
2432
2452
PatchAndroidManifest ( GetAndroidApplicationId ( ) , null ) ;
2433
2453
Reresolve ( ) ;
2434
2454
}
0 commit comments