问题
I'm currently working on a libgdx andriod app using eclipse luna and attempting to display a banner ad through admob.
My app is running fine and displaying the test banner ads with no issues.
When I remove my phone as a test device to receive live ads I get this error in logcat:
There was a problem getting an ad response. ErrorCode: 0 Failed to load ad: 0
I've tested my app on a Galaxy Note 4 and a Samsung S5 both running android version 6.0.1. There are no custom ROMs or ad blockers on either device and the test ads work on both.
I followed this guide on implementation with some references from google's android guide.
Here is where I think the issue is..
Via my SDK Manager I have Google Play services revision 39 and Google Repository revision 44 installed.
The guide says to attach the google-play-services_lib located at:
C:\Users\...\AppData\Local\Android\sdk\extras\google\google_play_services
However the file no longer exists, after following the information from this answer to the problem, I found google-play-services_lib rev 29 and added it to my projects library which works. Does the Google Play Services revision on the SDK Manager matter if its different from the one I manually added?
Either way this shouldn't matter as the test ads are working, however I'm not sure, have I missed anything that might be causing this error?
I also asked for assistance from google groups (Google Mobile Ads SDK Developers) with no luck.
My app unit ID:
Ad Unit ID: ca-app-pub-3059505755009716/4168523587
Ap ID: ca-app-pub-3059505755009716~2178916381
My Java implementation (AndriodLauncher.java):
public class AndroidLauncher extends AndroidApplication implements AdsController {
private static final String BANNER_AD_UNIT_ID = "ca-app-pub-3059505755009716/4168523587";
// ca-app-pub-3059505755009716/8048823189
// ca-app-pub-3059505755009716/4168523587
AdView bannerAd;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
// Create a gameView and a bannerAd AdView
View gameView = initializeForView(new Boot(this), config);
setupAds();
// Define the layout
RelativeLayout layout = new RelativeLayout(this);
layout.addView(gameView, ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layout.addView(bannerAd, params);
setContentView(layout);
}
public void setupAds() {
bannerAd = new AdView(this);
bannerAd.setVisibility(View.GONE);
bannerAd.setBackgroundColor(Color.argb(0, 0, 0, 0)); // black
bannerAd.setAdUnitId(BANNER_AD_UNIT_ID);
bannerAd.setAdSize(AdSize.BANNER);
}
@Override
public void showBannerAd() {
runOnUiThread(new Runnable() {
@Override
public void run() {
bannerAd.setVisibility(View.VISIBLE);
AdRequest.Builder builder = new AdRequest.Builder();
//builder.addTestDevice("9F2779F709CED00E2ADF6123C0D17A4C");
//builder.addTestDevice("ECDD91BD30440E7B3F4DA0E90F1D67A9");
AdRequest ad = builder.build();
bannerAd.loadAd(ad);
}
});
}
@Override
public void hideBannerAd() {
runOnUiThread(new Runnable() {
@Override
public void run() {
bannerAd.setVisibility(View.INVISIBLE);
}
});
}
}
Snippet of where the showBannerAd()
method is called:
public Boot(AdsController adsController){
this.adsController = adsController;
}
@Override
public void create() {
//Gdx.app.log(TITLE, "started..");
// Display ads (andriod launch)
adsController.showBannerAd();
setScreen(new Splash());
Timer.schedule(new Task(){
@Override
public void run() {
assets = new Assets();
assets.load();
assets.manager.finishLoading();
Audio.create();
Audio.bgm.play();
Audio.bgm.setLooping(true);
setScreen(new MainMenu());
}
}, 3f);
}
AndriodManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.game"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="25" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/GdxTheme" >
<activity
android:name="com.game.AndroidLauncher"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
EDIT : Noticed the line
compile 'com.google.android.gms:play-services-ads:10.0.1'
was missing from the android dependencies within build.grandle, refreshed dependencies still no live ads.
回答1:
According to Google
"It could be that you have only recently created a new Ad Unit ID and requesting for live ads. It could take a few hours for ads to start getting served if that is that case. If you are receiving test ads then your implementation is fine. Just wait a few hours and see if you are able to receive live ads then. If not, can send us your Ad Unit ID for us to look into."
https://groups.google.com/forum/#!category-topic/google-admob-ads-sdk/android/fBe3YL3ffpo
so wait for a few hours.
来源:https://stackoverflow.com/questions/42688617/admob-live-ads-not-appearing-in-libgdx-application-failed-to-load-ad-0