public void OnPostGenerateGradleAndroidProject(string path)
        {
            if (!PlayInstantBuildConfiguration.IsInstantBuildType())
            {
                return;
            }

            // Update the final merged AndroidManifest.xml prior to the gradle build.
            var manifestPath = Path.Combine(path, "src/main/AndroidManifest.xml");

            Debug.LogFormat("Updating manifest for Play Instant: {0}", manifestPath);

            Uri uri        = null;
            var instantUrl = PlayInstantBuildConfiguration.InstantUrl;

            if (!string.IsNullOrEmpty(instantUrl))
            {
                uri = new Uri(instantUrl);
            }

            var doc          = XDocument.Load(manifestPath);
            var errorMessage = AndroidManifestHelper.ConvertManifestToInstant(doc, uri);

            if (errorMessage != null)
            {
                PlayInstantBuilder.DisplayBuildError(
                    string.Format("Error updating AndroidManifest.xml: {0}", errorMessage));
                return;
            }

            doc.Save(manifestPath);
        }
        public string SwitchToInstant(Uri uri)
        {
            XDocument doc;

            if (File.Exists(AndroidManifestAssetsPath))
            {
                Debug.LogFormat("Loading existing file {0}", AndroidManifestAssetsPath);
                doc = XDocument.Load(AndroidManifestAssetsPath);
            }
            else
            {
                Debug.Log("Creating new manifest file");
                doc = AndroidManifestHelper.CreateManifestXDocument();
            }

            var errorMessage = AndroidManifestHelper.ConvertManifestToInstant(doc, uri);

            if (errorMessage != null)
            {
                return(errorMessage);
            }

            if (!Directory.Exists(AndroidManifestAssetsDirectory))
            {
                Directory.CreateDirectory(AndroidManifestAssetsDirectory);
            }

            doc.Save(AndroidManifestAssetsPath);

            Debug.LogFormat("Successfully updated {0}", AndroidManifestAssetsPath);
            return(null);
        }
        public void SwitchToInstalled()
        {
            if (!File.Exists(AndroidManifestAssetsPath))
            {
                Debug.LogFormat("Nothing to do for {0} since file does not exist", AndroidManifestAssetsPath);
                return;
            }

            Debug.LogFormat("Loading existing file {0}", AndroidManifestAssetsPath);
            var doc = XDocument.Load(AndroidManifestAssetsPath);

            AndroidManifestHelper.ConvertManifestToInstalled(doc);
            doc.Save(AndroidManifestAssetsPath);
            Debug.LogFormat("Successfully updated {0}", AndroidManifestAssetsPath);
        }
        public string CheckInstantManifest()
        {
            if (!File.Exists(AndroidManifestAssetsPath))
            {
                return(string.Format("Failed to locate file {0}", AndroidManifestAssetsPath));
            }

            string errorMessage;
            var    doc = XDocument.Load(AndroidManifestAssetsPath);
            var    hasCurrentPluginVersion = AndroidManifestHelper.HasCurrentPluginVersion(doc, out errorMessage);

            if (errorMessage != null)
            {
                return(errorMessage);
            }

            if (!hasCurrentPluginVersion)
            {
                doc.Save(AndroidManifestAssetsPath);
                Debug.LogFormat("Successfully updated {0}", AndroidManifestAssetsPath);
            }

            return(null);
        }