- Home /
Question by
FerdinandBuagas · Oct 24, 2017 at 10:52 AM ·
admobdevelopment build
Unable to Show Admob ads | Development Build
Hello Guys,
I would like to ask for advice. I am able to see the admob ads in my emulator and also with real device, if in my Build Settings the Development Build is Checked.
But if not, no Ads at all.
Will it be okay to build an APK to be released in Google Play Store even if the Development Build is checked?
Sorry I'm new in Unity.
The Code:
using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;
public class AdScript : MonoBehaviour
{
bool isShown;
InterstitialAd interstitial;
void Start()
{
RequestInterstitialAds();
}
void Update()
{
if (GameControl.isGameOver)
{
if (!isShown)
{
isShown = true;
showInterstitialAd();
}
}
}
public void showInterstitialAd()
{
if (interstitial.IsLoaded())
{
interstitial.Show();
}
}
private void RequestInterstitialAds()
{
//Testing
string adID = "ca-app-pub-3940256099942544/1033173712";
//Live
//string adID = "MY ADD ID";
#if UNITY_ANDROID
string adUnitId = adID;
#elif UNITY_IOS
string adUnitId = adID;
#else
string adUnitId = adID;
#endif
// Initialize an InterstitialAd.
interstitial = new InterstitialAd(adUnitId);
//Test
AdRequest request = new AdRequest.Builder()
.AddTestDevice(AdRequest.TestDeviceSimulator) // Simulator.
.AddTestDevice("89D1DA1F820CE28BA86223A1C34****") // My test device.
.Build();
//Production
//AdRequest request = new AdRequest.Builder().Build();
//Register Ad Close Event
interstitial.OnAdClosed += Interstitial_OnAdClosed;
//Load the interstitial with the request.
interstitial.LoadAd(request);
//Debug.Log("AD LOADED XXX");
}
private void Interstitial_OnAdClosed(object sender, System.EventArgs e)
{
//Resume Play Sound
}
}
Thanks in advance.
development-build.jpg
(21.6 kB)
Comment
Answer by FerdinandBuagas · Nov 01, 2017 at 06:03 AM
To those who encounters this error:
enable the "User Proguard File", Then on the proguard-user.txt. add this.
-keep public class com.google.android.gms.ads.{
public *;
}
# For old ads classes
-keep public class com.google.ads.{
public *;
}
# For mediation
-keepattributes Annotation
# Other required classes for Google Play Services
# Read more at http://developer.android.com/google/play-services/setup.html
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final * NULL;
}
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
@com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
public static final CREATOR;
}
-keep public class com.google.unity.**{
public *;
}
Note: This does solve my issue, But I'm not sure how will this code affect the project, Anyone have an idea? Need advice on this.
By the way I found this here: https://github.com/googleads/googleads-mobile-unity/issues/539
Your answer
![](https://koobas.hobune.stream/wayback/20220612141733im_/https://answers.unity.com/themes/thub/images/avi.jpg)