private void SaveConfig() { if (selectPlarformTab == PlatfromTab.Android) { if (Yodo1PostProcess.CheckConfiguration_Android(this.adSettings)) { #if UNITY_2019_1_OR_NEWER #else Yodo1PostProcess.ValidateManifest(this.adSettings); Yodo1PostProcess.GenerateGradle(); #endif } else { return; } } if (selectPlarformTab == PlatfromTab.iOS) { if (!Yodo1PostProcess.CheckConfiguration_iOS(this.adSettings)) { return; } } Yodo1AdSettingsSave.Save(this.adSettings); Yodo1AdSettingsSave.UpdateDependencies(this.adSettings); }
static void Yodo1ValidateManifest(string path) { var mainfestPath = Path.Combine(path, "src/main/AndroidManifest.xml"); if (mainfestPath.Contains("unityLibrary")) { mainfestPath = mainfestPath.Replace("unityLibrary", "launcher"); } if (File.Exists(mainfestPath)) { Yodo1AdSettings settings = Yodo1AdSettingsSave.Load(); if (Yodo1PostProcess.CheckConfiguration_Android(settings)) { ValidateManifest(mainfestPath, settings); } } }
static void ValidateManifest(string manifestFile, Yodo1AdSettings settings) { XmlDocument doc = new XmlDocument(); doc.Load(manifestFile); if (doc == null) { Debug.LogError("[Yodo1 Mas] Couldn't load " + manifestFile); return; } XmlNode manNode = Yodo1PostProcess.FindChildNode(doc, "manifest"); string ns = manNode.GetNamespaceOfPrefix("android"); XmlNode app = Yodo1PostProcess.FindChildNode(manNode, "application"); if (app == null) { Debug.LogError("[Yodo1 Mas] Error parsing " + manifestFile + ", tag for application not found."); return; } ////Enable hardware acceleration for video play //XmlElement elem = (XmlElement)app; //Add AdMob App ID if (settings.androidSettings.GooglePlayStore) { string admobAppIdValue = settings.androidSettings.AdmobAppID.Trim(); if (string.IsNullOrEmpty(admobAppIdValue)) { Debug.LogError("[Yodo1 Mas] MAS Android AdMob App ID is null, please check the configuration."); return; } string admobAppIdName = "com.google.android.gms.ads.APPLICATION_ID"; XmlNode metaNode = Yodo1PostProcess.FindChildNodeWithAttribute(app, "meta-data", "android:name", admobAppIdName); if (metaNode == null) { metaNode = (XmlElement)doc.CreateNode(XmlNodeType.Element, "meta-data", null); app.AppendChild(metaNode); } XmlElement metaElement = (XmlElement)metaNode; metaElement.SetAttribute("name", ns, admobAppIdName); metaElement.SetAttribute("value", ns, admobAppIdValue); metaElement.GetNamespaceOfPrefix("android"); } //Add Channel string channelValue = string.Empty; if (settings.androidSettings.ChineseAndroidStores) { channelValue = settings.androidSettings.Channel.Trim(); if (string.IsNullOrEmpty(channelValue)) { Debug.LogError("[Yodo1 Mas] MAS Android Channel is null, please check the configuration."); return; } } if (settings.androidSettings.GooglePlayStore) { channelValue = "GooglePlay"; } string channelName = "Yodo1ChannelCode"; XmlNode meta1Node = Yodo1PostProcess.FindChildNodeWithAttribute(app, "meta-data", "android:name", channelName); if (meta1Node == null) { meta1Node = (XmlElement)doc.CreateNode(XmlNodeType.Element, "meta-data", null); app.AppendChild(meta1Node); } XmlElement meta1Element = (XmlElement)meta1Node; meta1Element.SetAttribute("name", ns, channelName); meta1Element.SetAttribute("value", ns, channelValue); meta1Element.GetNamespaceOfPrefix("android"); string ns2 = manNode.GetNamespaceOfPrefix("tools"); meta1Element.SetAttribute("replace", ns2, "android:value"); doc.Save(manifestFile); }