private static List <string> ReadGradleFile(string prefix, string path)
        {
            try
            {
                if (File.Exists(path))
                {
                    return(new List <string>(File.ReadAllLines(path)));
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

            var message = "A successful build requires do modifications to " + prefix + " template. " +
                          "But the template is not activated now.";

            Utils.DialogOrCancelBuild(message + "\nClick Сontinue to activate.", BuildTarget.NoTarget);
            try
            {
                if (TryEnableGradleTemplate(path) && File.Exists(path))
                {
                    return(new List <string>(File.ReadAllLines(path)));
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
            Utils.StopBuildWithMessage(message, BuildTarget.NoTarget);
            return(null);
        }
        public static void ConfigureProject(BuildTarget target, CASEditorSettings editorSettings)
        {
            if (target != BuildTarget.Android && target != BuildTarget.iOS)
            {
                return;
            }

            var settings = Utils.GetSettingsAsset(target, false);

            if (!settings)
            {
                Utils.StopBuildWithMessage("Settings asset not found. Please use menu Assets > CleverAdsSolutions > Settings " +
                                           "to create and set settings for build.", target);
            }

            var deps = DependencyManager.Create(target, Audience.Mixed, true);

            if (!Application.isBatchMode)
            {
                var newCASVersion = Utils.GetNewVersionOrNull(Utils.gitUnityRepo, MobileAds.wrapperVersion, false);
                if (newCASVersion != null)
                {
                    Utils.DialogOrCancelBuild("There is a new version " + newCASVersion + " of the CAS Unity available for update.", target);
                }

                if (deps != null)
                {
                    if (!deps.installedAny)
                    {
                        Utils.StopBuildWithMessage("Dependencies of native SDK were not found. " +
                                                   "Please use 'Assets > CleverAdsSolutions > Settings' menu to integrate solutions or any SDK separately.", target);
                    }

                    if (deps.IsNewerVersionFound())
                    {
                        Utils.DialogOrCancelBuild("There is a new versions of the native dependencies available for update." +
                                                  "Please use 'Assets > CleverAdsSolutions >Settings' menu to update.", target);
                    }
                }
            }

            if (settings.managersCount == 0 || string.IsNullOrEmpty(settings.GetManagerId(0)))
            {
                StopBuildIDNotFound(target);
            }

            string admobAppId = UpdateRemoteSettingsAndGetAppId(settings, target, deps);

            if (target == BuildTarget.Android)
            {
                ConfigureAndroid(settings, editorSettings, admobAppId);
            }
            else if (target == BuildTarget.iOS)
            {
                ConfigureIOS();
            }

#pragma warning disable CS0618 // Type or member is obsolete
            // Use directrly property to avoid Debug build
            if (settings.testAdMode && !EditorUserBuildSettings.development)
            {
                Debug.LogWarning(Utils.logTag + "Test Ads Mode enabled! Make sure the build is for testing purposes only!\n" +
                                 "Use 'Assets > CleverAdsSolutions > Settings' menu to disable Test Ad Mode.");
            }
            else
            {
                Debug.Log(Utils.logTag + "Project configuration completed");
            }
#pragma warning restore CS0618 // Type or member is obsolete
        }
 private static void StopBuildIDNotFound(BuildTarget target)
 {
     Utils.StopBuildWithMessage("Settings not found manager ids for " + target.ToString() +
                                " platform. For a successful build, you need to specify at least one ID" +
                                " that you use in the project. To test integration, you can use test mode with 'demo' manager id.", target);
 }
        private static string UpdateRemoteSettingsAndGetAppId(CASInitSettings settings, BuildTarget platform, DependencyManager deps)
        {
            string appId = null;
            string updateSettingsError = "";

            for (int i = 0; i < settings.managersCount; i++)
            {
                var managerId = settings.GetManagerId(i);
                if (managerId == null || managerId.Length < 5)
                {
                    continue;
                }
                try
                {
                    string newAppId = DownloadRemoteSettings(managerId, platform, settings, deps);
                    if (!string.IsNullOrEmpty(appId) || string.IsNullOrEmpty(newAppId))
                    {
                        continue;
                    }
                    if (newAppId.Contains('~'))
                    {
                        appId = newAppId;
                        continue;
                    }
                    if (i == 0)
                    {
                        Debug.LogError(Utils.logTag + "CAS id [" + managerId +
                                       "] has an error in server settings. Please contact support!");
                    }
                }
                catch (Exception e)
                {
                    updateSettingsError = e.Message;
                }
            }
            if (!string.IsNullOrEmpty(appId) || settings.IsTestAdMode())
            {
                return(appId);
            }

            const string title          = "Update CAS remote settings";
            int          dialogResponse = 0;
            var          targetId       = settings.GetManagerId(0);

            var message = updateSettingsError +
                          "\nPlease try using a real identifier in the first place else contact support." +
                          "\n- Warning! -" +
                          "\n1. Continue build the app for release with current settings can reduce monetization revenue." +
                          "\n2. When build to testing your app, make sure you use Test Ads mode rather than live ads. " +
                          "Failure to do so can lead to suspension of your account.";

            Debug.LogError(Utils.logTag + message);
            if (!Application.isBatchMode)
            {
                dialogResponse = EditorUtility.DisplayDialogComplex(title, message,
                                                                    "Continue", "Cancel Build", "Select settings file");
            }

            if (dialogResponse == 0)
            {
                var cachePath = Utils.GetNativeSettingsPath(platform, targetId);
                if (File.Exists(cachePath))
                {
                    return(Utils.GetAdmobAppIdFromJson(File.ReadAllText(cachePath)));
                }
                return(null);
            }
            if (dialogResponse == 1)
            {
                Utils.StopBuildWithMessage("Build canceled", BuildTarget.NoTarget);
                return(null);
            }
            return(Utils.SelectSettingsFileAndGetAppId(targetId, platform));
        }