示例#1
0
        public static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath)
        {
            var appId = MaxMediationGoogleUtils.GetAppIdFromAppLovinSettings("AdMobIosAppId");

            // Log error if the App ID is not set.
            if (string.IsNullOrEmpty(appId) || !appId.StartsWith("ca-app-pub-"))
            {
                Debug.LogError("[AppLovin MAX] AdMob App ID is not set. Please enter a valid app ID within the AppLovin Integration Manager window.");
                return;
            }

            var plistPath = Path.Combine(buildPath, "Info.plist");
            var plist     = new PlistDocument();

            plist.ReadFromFile(plistPath);

            // Actually set (then write) AdMob app id to Info.plist if valid
            plist.root.SetString("GADApplicationIdentifier", appId);

            File.WriteAllText(plistPath, plist.WriteToString());
        }
示例#2
0
        public void OnPreprocessBuild(BuildTarget target, string path)
#endif
        {
            var appId = MaxMediationGoogleUtils.GetAppIdFromAppLovinSettings("AdMobAndroidAppId");

            if (string.IsNullOrEmpty(appId))
            {
                Debug.LogError("[AppLovin MAX] AdMob App ID is not set. Please enter a valid app ID within the ");
                return;
            }

            var manifestPath = Path.Combine(Application.dataPath, "Plugins/Android/MaxMediationGoogle/AndroidManifest.xml");

            XDocument manifest;

            try
            {
                manifest = XDocument.Load(manifestPath);
            }
#pragma warning disable 0168
            catch (IOException exception)
#pragma warning restore 0168
            {
                Debug.LogError("[AppLovin MAX] Google mediation AndroidManifest.xml is missing. Ensure that MAX Google mediation plugin is imported correctly.");
                return;
            }

            // Get the `manifest` element.
            var elementManifest = manifest.Element("manifest");
            if (elementManifest == null)
            {
                Debug.LogError("[AppLovin MAX] Google mediation AndroidManifest.xml is invalid. Ensure that MAX Google mediation plugin is imported correctly.");
                return;
            }

            // Get the `application` element under `manifest`.
            var elementApplication = elementManifest.Element("application");
            if (elementApplication == null)
            {
                Debug.LogError("[AppLovin MAX] Google mediation AndroidManifest.xml is invalid. Ensure that MAX Google mediation plugin is imported correctly.");
                return;
            }

            // Get all the `meta-data` elements under `application`.
            var        adMobMetaData    = elementApplication.Descendants().First(element => element.Name.LocalName.Equals("meta-data"));
            XNamespace androidNamespace = "http://schemas.android.com/apk/res/android";

            if (!adMobMetaData.FirstAttribute.Name.Namespace.Equals(androidNamespace) ||
                !adMobMetaData.FirstAttribute.Name.LocalName.Equals("name") ||
                !adMobMetaData.FirstAttribute.Value.Equals("com.google.android.gms.ads.APPLICATION_ID"))
            {
                Debug.LogError("[AppLovin MAX] Google mediation AndroidManifest.xml is invalid. Ensure that MAX Google mediation plugin is imported correctly.");
                return;
            }

            var lastAttribute = adMobMetaData.LastAttribute;
            // Log error if the AdMob App ID is not set.
            if (!lastAttribute.Name.LocalName.Equals("value"))
            {
                Debug.LogError("[AppLovin MAX] Google mediation AndroidManifest.xml is invalid. Ensure that MAX Google mediation plugin is imported correctly.");
            }

            // Set the App ID value.
            lastAttribute.Value = appId;

            // Save the updated manifest file.
            manifest.Save(manifestPath);
        }