static GenerateXmlFromGoogleServicesJson() { GenerateXmlFromGoogleServicesJson.executable_Name_Windows = "generate_xml_from_google_services_json.exe"; GenerateXmlFromGoogleServicesJson.executable_Name_Generic = "generate_xml_from_google_services_json.py"; GenerateXmlFromGoogleServicesJson.plugin_name = "Firebase/Firebase"; GenerateXmlFromGoogleServicesJson.executable_Location = Path.Combine(Path.Combine("Assets", GenerateXmlFromGoogleServicesJson.plugin_name), "Editor"); GenerateXmlFromGoogleServicesJson.google_Services_File_BaseName = "google-services"; GenerateXmlFromGoogleServicesJson.google_services_input_file = GenerateXmlFromGoogleServicesJson.google_Services_File_BaseName + ".json"; GenerateXmlFromGoogleServicesJson.google_services_output_file = GenerateXmlFromGoogleServicesJson.google_Services_File_BaseName + ".xml"; GenerateXmlFromGoogleServicesJson.google_services_output_directory = Path.Combine(Path.Combine(Path.Combine(Path.Combine(Path.Combine("Assets", "Plugins"), "Android"), "Firebase"), "res"), "values"); GenerateXmlFromGoogleServicesJson.google_services_output_path = Path.Combine(GenerateXmlFromGoogleServicesJson.google_services_output_directory, GenerateXmlFromGoogleServicesJson.google_services_output_file); GenerateXmlFromGoogleServicesJson.google_service_info_file_basename = "GoogleService-Info"; GenerateXmlFromGoogleServicesJson.google_service_info_input_file = GenerateXmlFromGoogleServicesJson.google_service_info_file_basename + ".plist"; GenerateXmlFromGoogleServicesJson.google_services_desktop_output_file = GenerateXmlFromGoogleServicesJson.google_Services_File_BaseName + "-desktop.json"; GenerateXmlFromGoogleServicesJson.google_services_desktop_output_directory = Path.Combine("Assets", "StreamingAssets"); GenerateXmlFromGoogleServicesJson.google_services_desktop_output_path = Path.Combine(GenerateXmlFromGoogleServicesJson.google_services_desktop_output_directory, GenerateXmlFromGoogleServicesJson.google_services_desktop_output_file); GenerateXmlFromGoogleServicesJson.newline_chars = new char[] { '\r', '\n' }; GenerateXmlFromGoogleServicesJson.field_delimiter = new char[] { '=' }; GenerateXmlFromGoogleServicesJson.ConfigFileDirectory = new SortedDictionary <string, List <string> >(); if (VersionHandler.GetUnityVersionMajorMinor() >= 5f) { GenerateXmlFromGoogleServicesJson.CheckConfiguration(); } else { Delegate arg_182_0 = EditorApplication.update; if (GenerateXmlFromGoogleServicesJson.f__mgcache0 == null) { GenerateXmlFromGoogleServicesJson.f__mgcache0 = new EditorApplication.CallbackFunction(GenerateXmlFromGoogleServicesJson.CheckConfiguration); } EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Remove(arg_182_0, GenerateXmlFromGoogleServicesJson.f__mgcache0); Delegate arg_1B3_0 = EditorApplication.update; if (GenerateXmlFromGoogleServicesJson.f__mgcache1 == null) { GenerateXmlFromGoogleServicesJson.f__mgcache1 = new EditorApplication.CallbackFunction(GenerateXmlFromGoogleServicesJson.CheckConfiguration); } EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Combine(arg_1B3_0, GenerateXmlFromGoogleServicesJson.f__mgcache1); } if (GenerateXmlFromGoogleServicesJson.f__mgcache2 == null) { GenerateXmlFromGoogleServicesJson.f__mgcache2 = new EventHandler <PlayServicesResolver.BundleIdChangedEventArgs>(GenerateXmlFromGoogleServicesJson.OnBundleIdChanged); } //PlayServicesResolver.remove_BundleIdChanged(GenerateXmlFromGoogleServicesJson.f__mgcache2); PlayServicesResolver.BundleIdChanged -= GenerateXmlFromGoogleServicesJson.f__mgcache2; if (GenerateXmlFromGoogleServicesJson.f__mgcache3 == null) { GenerateXmlFromGoogleServicesJson.f__mgcache3 = new EventHandler <PlayServicesResolver.BundleIdChangedEventArgs>(GenerateXmlFromGoogleServicesJson.OnBundleIdChanged); } //PlayServicesResolver.add_BundleIdChanged(GenerateXmlFromGoogleServicesJson.f__mgcache3); PlayServicesResolver.BundleIdChanged += GenerateXmlFromGoogleServicesJson.f__mgcache3; }
/// <summary> /// Inject / update dependencies in the gradle template file. /// </summary> /// <param name="dependencies">Dependencies to inject.</param> /// <returns>true if successful, false otherwise.</returns> public static bool InjectDependencies(ICollection <Dependency> dependencies) { var resolutionMeasurementParameters = PlayServicesResolver.GetResolutionMeasurementParameters(null); if (dependencies.Count > 0) { PlayServicesResolver.analytics.Report( "/resolve/gradletemplate", resolutionMeasurementParameters, "Gradle Template Resolve"); } var fileDescription = String.Format("gradle template {0}", GradleTemplatePath); PlayServicesResolver.Log(String.Format("Reading {0}", fileDescription), level: LogLevel.Verbose); IEnumerable <string> lines; try { lines = File.ReadAllLines(GradleTemplatePath); } catch (Exception ex) { PlayServicesResolver.analytics.Report( "/resolve/gradletemplate/failed/templateunreadable", "Gradle Template Resolve: Failed Template Unreadable"); PlayServicesResolver.Log( String.Format("Unable to patch {0} ({1})", fileDescription, ex.ToString()), level: LogLevel.Error); return(false); } PlayServicesResolver.Log(String.Format("Searching for {0} in {1}", DependenciesToken, fileDescription), level: LogLevel.Verbose); // Determine whether dependencies should be injected. var dependenciesToken = new Regex(DependenciesToken); bool containsDeps = false; foreach (var line in lines) { if (dependenciesToken.IsMatch(line)) { containsDeps = true; break; } } // If a dependencies token isn't present report a warning and abort. if (!containsDeps) { PlayServicesResolver.analytics.Report( "/resolve/gradletemplate/failed/noinjectionpoint", "Gradle Template Resolve: Failed No Injection Point"); PlayServicesResolver.Log( String.Format("No {0} token found in {1}, Android Resolver libraries will " + "not be added to the file.", DependenciesToken, fileDescription), level: LogLevel.Warning); return(true); } // Copy all srcaar files in the project to aar filenames so that they'll be included in // the Gradle build. if (!CopySrcAars(dependencies)) { PlayServicesResolver.analytics.Report( "/resolve/gradletemplate/failed/srcaarcopy", "Gradle Template Resolve: Failed srcaar I/O"); return(false); } var repoLines = new List <string>(); // Optionally enable the jetifier. if (SettingsDialog.UseJetifier && dependencies.Count > 0) { // For Unity versions lower than 2019.3 add jetifier and AndroidX // properties to custom main gradle template if (VersionHandler.GetUnityVersionMajorMinor() < 2019.3f) { repoLines.AddRange(new [] { "([rootProject] + (rootProject.subprojects as List)).each {", " ext {", " it.setProperty(\"android.useAndroidX\", true)", " it.setProperty(\"android.enableJetifier\", true)", " }", "}" }); } } repoLines.AddRange(PlayServicesResolver.GradleMavenReposLines(dependencies)); TextFileLineInjector[] injectors = new [] { new TextFileLineInjector(ReposInjectionLine, ReposStartLine, ReposEndLine, repoLines, "Repos", fileDescription), new TextFileLineInjector(DependenciesToken, DependenciesStartLine, DependenciesEndLine, PlayServicesResolver.GradleDependenciesLines( dependencies, includeDependenciesBlock: false), "Dependencies", fileDescription), new TextFileLineInjector(PackagingOptionsToken, PackagingOptionsStartLine, PackagingOptionsEndLine, PlayServicesResolver.PackagingOptionsLines(dependencies), "Packaging Options", fileDescription), }; return(PatchFile(GradleTemplatePath, fileDescription, "Gradle Template", "gradletemplate", injectors, resolutionMeasurementParameters)); }