I got the new SDK for Admob recently, and I downloaded and loaded the package into my unity, and I keep getting this error each time:
Assets/GoogleMobileAds/Api/CustomNativeTemplateAd.cs(53,26): error CS0117: Utils' does not contain a definition forGetTexture2DFromByteArray'
However, in my Utils script, I have:
using System;
using UnityEngine;
namespace GoogleMobileAds.Common
{
internal class Utils
{
public static Texture2D GetTexture2DFromByteArray(byte[] img)
{
// Create a texture. Texture size does not matter, since
// LoadImage will replace with with incoming image size.
Texture2D nativeAdTexture = new Texture2D(1, 1);
if (!nativeAdTexture.LoadImage(img))
{
throw new InvalidOperationException(@"Could not load custom native template
image asset as texture");
}
return nativeAdTexture;
}
}
}
Any help is greatly appreciated
Within the CustomNativeTemplateAd class, when you right click on the class name Utils and select 'Go to Declaration' on the line Utils.GetTexture2DFromByteArray(imageAssetAsByteArray);, are you taken to the GoogleMobileAds.Common.Util class?
Hey rampara, sorry for the delay.
When I do 'Go to Declaration', it takes me to Assets.Utils, as in there is a script called Utils at the highest most folder. As well, there ALSO is a GoogleMobileAds.Common.Utils class, which is the script that I linked above, so essentially there are 2 different Utils scripts.
Now the Assets.Utils script is completely different from the GoogleMobileAds.Common.Utils (aka the one linked above).
Here it is:
public static class Utils
{
public static string ReadCustomString(this BinaryReader reader)
{
int length = (int)reader.ReadUInt32();
byte[] bytes = reader.ReadBytes(length);
return Encoding.UTF8.GetString(bytes);
}
public static void CopyToStream(Stream src, Stream dst, byte[] buffer, int numBytes)
{
while (numBytes > 0)
{
int req = Math.Min(buffer.Length, numBytes);
int read = src.Read(buffer, 0, req);
dst.Write(buffer, 0, read);
numBytes -= read;
}
}
internal static Texture2D GetTexture2DFromByteArray(byte[] imageAssetAsByteArray)
{
throw new NotImplementedException();
}
}
It sounds like you have a namespace conflict. Can you try updating line 53 of CustomNativeTemplateAd.cs from return Utils.GetTexture2DFromByteArray(imageAssetAsByteArray); to return GoogleMobileAds.Common.Utils.GetTexture2DFromByteArray(imageAssetAsByteArray);
Ok, adding 'GoogleMobileAds.Common.' in front has stopped it from throwing me an error.
I'm going to continue trying to implement the script to make sure that all is well, and if it looks like that's the case then I will go ahead and close the thread.
thank you very much
Closing this issue as it seems to be resolved. Please re-open if this issue still persists for you.
Why is this not addressed on current release?
Assets/GoogleMobileAds/Api/RewardedAd.cs(74,51): error CS1503: Argument #2' cannot convertReward' expression to type `GoogleMobileAds.Api.Reward'
how to solve it? Is my reward word used in gameplay code making trouble to admob?
i have just imported admob ads plugin in my unity 2014.4.31f1 and its giving error "Assets/GoogleMobileAds/Api/AdLoader.cs(42,19): error CS0117: Utils' does not contain a definition forCheckInitialization'"
there are two utile classes, Assets. Utils script is completely different from the GoogleMobileAds.Common.Utils, should I delete one of them?
I had this issue and solved it by adding namespace to my Utils class as it conflicted with GoogleMobileAds' Utils class.
Most helpful comment
Within the CustomNativeTemplateAd class, when you right click on the class name
Utilsand select 'Go to Declaration' on the lineUtils.GetTexture2DFromByteArray(imageAssetAsByteArray);, are you taken to the GoogleMobileAds.Common.Util class?