public static AndroidSdkManager GetAndroidSdk(bool useGlobalSdk = true) { lock (sdkLocker) { if (useGlobalSdk) { var globalSdk = AndroidSdkManager.FindHome()?.FirstOrDefault(); if (globalSdk != null && globalSdk.Exists) { AndroidSdkHome = globalSdk; } } if (AndroidSdkHome == null || !AndroidSdkHome.Exists) { var sdkPath = Path.Combine(TestDataDirectory, "android-sdk"); if (!Directory.Exists(sdkPath)) { Directory.CreateDirectory(sdkPath); } AndroidSdkHome = new DirectoryInfo(sdkPath); var s = new AndroidSdkManager(AndroidSdkHome); s.Acquire(); Assert.True(s.SdkManager.IsUpToDate()); } return(new AndroidSdkManager(AndroidSdkHome)); } }
/// <summary> /// Installs the specified Android SDK package. /// </summary> public static void InstallPackage(string packageName, string displayName, string androidSdkRoot) { // In many cases the SDK install is quick and clearly indicates download/install progress. However, on // some systems it can take a couple minutes and not indicate progress - set expectations with a dialog. // TODO: figure out if we can target this message only for when it is needed. const string message = "On some systems the install process is slow and does not provide feedback, " + "which may lead you to believe that Unity has frozen or crashed.\n\n" + "Click \"OK\" to continue."; if (!EditorUtility.DisplayDialog( "Install Note", message, WindowUtils.OkButtonText, WindowUtils.CancelButtonText)) { Debug.LogFormat("Cancelled install of {0}", displayName); return; } AndroidSdkManager.Create(androidSdkRoot, manager => { manager.QueryPackages(collection => { var package = collection.GetMostRecentAvailablePackage(packageName); if (package == null) { ShowMessage(string.Format("Unable to locate the {0} package", displayName)); return; } if (package.Installed) { ShowMessage(string.Format( "The {0} package is already installed at the latest available version ({1})", displayName, package.VersionString)); return; } var packages = new HashSet <AndroidSdkPackageNameVersion> { package }; manager.InstallPackages(packages, success => { if (success) { ShowMessage(string.Format("Successfully updated the {0} package to version {1}", displayName, package.VersionString)); } else { ShowMessage(string.Format("Failed to install the {0} package", displayName)); } }); }); }); }