Quantcast
Channel: Questions in topic: "admob"
Viewing all articles
Browse latest Browse all 137

Getting Error in Empty Project after importing GoogleMobileAds-v7.1.0

$
0
0
Hi Everyone, I have created a new project in Unity 2018.3.0f2 (64-bit) personal and converted that project to android and then imported GoogleMobileAds-v7.1.0 but after importing I received these errors in two files "BuildPreProcessor" and "ManifestProcessor". Errors Are: `Assets/GoogleMobileAds/Editor/ManifestProcessor.cs(22,19): error CS0234: The type or namespace name Build' does not exist in the namespace 'UnityEditor'. Are you missing an assembly reference?` `Assets/GoogleMobileAds/Editor/BuildPreProcessor.cs(3,19): error CS0234: The type or namespace name Build does not exist in the namespace 'UnityEditor'. Are you missing an assembly reference?` I tried putting these files in a separate folder under the asset with the name "Editor" but the problem didn't resolve. //File Name BuildPreProcessor.cs using System; using UnityEditor; using UnityEditor.Build; using UnityEditor.Build.Reporting; using UnityEngine; #if UNITY_2018_1_OR_NEWER using UnityEditor.Build.Reporting; #endif using UnityEditor.Callbacks; using GoogleMobileAds.Editor; #if UNITY_2018_1_OR_NEWER public class BuildPreProcessor : IPreprocessBuildWithReport #else public class BuildPreProcessor : IPreprocessBuild #endif { public int callbackOrder { get { return 1; } } #if UNITY_2018_1_OR_NEWER public void OnPreprocessBuild(BuildReport report) #else public void OnPreprocessBuild(BuildTarget target, string path) #endif { if (!AssetDatabase.IsValidFolder("Assets/GoogleMobileAds")) { AssetDatabase.CreateFolder("Assets", "GoogleMobileAds"); } if (AssetDatabase.IsValidFolder("Packages/com.google.ads.mobile")) { AssetDatabase.CopyAsset("Packages/com.google.ads.mobile/GoogleMobileAds/link.xml", "Assets/GoogleMobileAds/link.xml"); } } } //File Name ManifestProcessor.cs // Copyright (C) 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #if UNITY_ANDROID using System.Collections.Generic; using System.IO; using System.Linq; using System.Xml.Linq; using UnityEditor; using UnityEditor.Build; #if UNITY_2018_1_OR_NEWER using UnityEditor.Build.Reporting; #endif using UnityEngine; using GoogleMobileAds.Editor; #if UNITY_2018_1_OR_NEWER public class ManifestProcessor : IPreprocessBuildWithReport #else public class ManifestProcessor : IPreprocessBuild #endif { private const string META_APPLICATION_ID = "com.google.android.gms.ads.APPLICATION_ID"; private const string MANIFEST_RELATIVE_PATH = "Plugins/Android/GoogleMobileAdsPlugin.androidlib/AndroidManifest.xml"; private const string META_DELAY_APP_MEASUREMENT_INIT = "com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT"; private XNamespace ns = "http://schemas.android.com/apk/res/android"; public int callbackOrder { get { return 0; } } #if UNITY_2018_1_OR_NEWER public void OnPreprocessBuild(BuildReport report) #else public void OnPreprocessBuild(BuildTarget target, string path) #endif { string manifestPath = Path.Combine( Application.dataPath, MANIFEST_RELATIVE_PATH); if (AssetDatabase.IsValidFolder("Packages/com.google.ads.mobile")) { manifestPath = Path.Combine("Packages/com.google.ads.mobile", MANIFEST_RELATIVE_PATH); } XDocument manifest = null; try { manifest = XDocument.Load(manifestPath); } #pragma warning disable 0168 catch (IOException e) #pragma warning restore 0168 { StopBuildWithMessage("AndroidManifest.xml is missing. Try re-importing the plugin."); } XElement elemManifest = manifest.Element("manifest"); if (elemManifest == null) { StopBuildWithMessage("AndroidManifest.xml is not valid. Try re-importing the plugin."); } XElement elemApplication = elemManifest.Element("application"); if (elemApplication == null) { StopBuildWithMessage("AndroidManifest.xml is not valid. Try re-importing the plugin."); } IEnumerable metas = elemApplication.Descendants() .Where( elem => elem.Name.LocalName.Equals("meta-data")); XElement elemGMAEnabled = GetMetaElement(metas, META_APPLICATION_ID); string appId = GoogleMobileAdsSettings.Instance.GoogleMobileAdsAndroidAppId; if (appId.Length == 0) { StopBuildWithMessage( "Android Google Mobile Ads app ID is empty. Please enter a valid app ID to run ads properly."); } if (elemGMAEnabled == null) { elemApplication.Add(CreateMetaElement(META_APPLICATION_ID, appId)); } else { elemGMAEnabled.SetAttributeValue(ns + "value", appId); } XElement elemDelayAppMeasurementInit = GetMetaElement(metas, META_DELAY_APP_MEASUREMENT_INIT); if (GoogleMobileAdsSettings.Instance.DelayAppMeasurementInit) { if (elemDelayAppMeasurementInit == null) { elemApplication.Add(CreateMetaElement(META_DELAY_APP_MEASUREMENT_INIT, true)); } else { elemDelayAppMeasurementInit.SetAttributeValue(ns + "value", true); } } else { if (elemDelayAppMeasurementInit != null) { elemDelayAppMeasurementInit.Remove(); } } elemManifest.Save(manifestPath); } private XElement CreateMetaElement(string name, object value) { return new XElement("meta-data", new XAttribute(ns + "name", name), new XAttribute(ns + "value", value)); } private XElement GetMetaElement(IEnumerable metas, string metaName) { foreach (XElement elem in metas) { IEnumerable attrs = elem.Attributes(); foreach (XAttribute attr in attrs) { if (attr.Name.Namespace.Equals(ns)&& attr.Name.LocalName.Equals("name") && attr.Value.Equals(metaName)) { return elem; } } } return null; } private void StopBuildWithMessage(string message) { string prefix = "[GoogleMobileAds] "; #if UNITY_2017_1_OR_NEWER throw new BuildPlayerWindow.BuildMethodException(prefix + message); #else throw new OperationCanceledException(prefix + message); #endif } } #endif these are the 2 files causing this problem and I have been stuck in this for the past 3 days. Thanks in Advance Regards Tariq

Viewing all articles
Browse latest Browse all 137

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>