0
\$\begingroup\$

I've been trying to include some ads in my app using AdMob. It all launches ok so i assume i have the library added correctly etc. I followed a tutorial that was over a year old (Brent Aureli on youtube) becoz that was all i could find relative to LibGDX.

It seems to try to pull the ad in , but can't display it. I can't make much more sense out of the log and would love if someone can help me out.

As a note, my game is in debug version (of course as i'm still developing it in Android Studio - but v1.0 is available on Play Store), i've added the Test Device as per the log. Usually (ie. before i added the adView code) the intro music plays right from the start. This still happens but as soon as i get the message on phone saying "signing into Google..." and the subsequent failure message (which is normal as its in debug) the music now stops and doesnt start again until i press my Play Game button.

I'm currently doing everything inside AndroidLauncher.

Here is the log: V/WebViewChromiumFactoryProvider: Binding Chromium to main looper Looper (main, tid 1) {d618180} I/LibraryLoader: Expected native library version number "",actual native library version number "" I/chromium: [INFO:library_loader_hooks.cc(104)] Chromium logging enabled: level = 0, default verbosity = 0 I/BrowserStartupController: Initializing chromium process, singleProcess=true W/art: Attempt to remove local handle scope entry from IRT, ignoring W/chromium: [WARNING:resource_bundle.cc(304)] locale_file_path.empty() I/chromium: [INFO:aw_browser_main_parts.cc(65)] Load from apk succesful, fd=61 off=43108 len=3029 I/chromium: [INFO:aw_browser_main_parts.cc(78)] Loading webviewchromium.pak from, fd:62 off:229484 len:1089587 W/AudioManagerAndroid: Requires BLUETOOTH permission W/chromium: [WARNING:data_reduction_proxy_settings.cc(331)] SPDY proxy OFF at startup W/art: Attempt to remove local handle scope entry from IRT, ignoring W/AwContents: onDetachedFromWindow called when already detached. Ignoring W/art: Attempt to remove local handle scope entry from IRT, ignoring W/art: Attempt to remove local handle scope entry from IRT, ignoring W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection W/art: Attempt to remove local handle scope entry from IRT, ignoring W/AwContents: onDetachedFromWindow called when already detached. Ignoring W/art: Attempt to remove local handle scope entry from IRT, ignoring W/art: Attempt to remove local handle scope entry from IRT, ignoring I/Ads: Ad finished loading. I/AndroidLauncher: ad loaded... I/chromium: [INFO:CONSOLE(0)] "Document was loaded from Application Cache with manifest https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.appcache", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0) I/chromium: [INFO:CONSOLE(0)] "Application Cache Checking event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0) I/chromium: [INFO:CONSOLE(0)] "Application Cache NoUpdate event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0) D/GameHelper: GameHelper: onActivityResult: req=RC_RESOLVE, resp=SIGN_IN_FAILED D/GameHelper: GameHelper: onAR: responseCode=SIGN_IN_FAILED, so giving up. W/GameHelper: disconnect() called when client was already disconnected. D/GameHelper: GameHelper: Notifying LISTENER of sign-in FAILURE (error) I/AndroidInput: sensor listener setup I/Ads: Scheduling ad refresh 60000 milliseconds from now. I/AndroidGraphics: resumed I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@36075376 time:451983293 I/Ads: Ad is not visible. Not refreshing ad. I/Ads: Scheduling ad refresh 60000 milliseconds from now. I/AndroidGraphics: paused I/AndroidInput: sensor listener tear down I/AndroidGraphics: Managed meshes/app: { } I/AndroidGraphics: Managed textures/app: { } I/AndroidGraphics: Managed cubemap/app: { } I/AndroidGraphics: Managed shaders/app: { } I/AndroidGraphics: Managed buffers/app: { } I/AndroidGraphics: destroyed W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection D/GameHelper: GameHelper: onStop D/GameHelper: GameHelper: Client already disconnected when we got onStop.

and my code:

public class AndroidLauncher extends AndroidApplication implements GameHelper.GameHelperListener, GoogInterface{
private final String TAG = "AndroidLauncher";
private GameHelper gameHelper;
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
FlapTurdGame game;





protected AdView adView;

@Override
public void onCreate (Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    game = new FlapTurdGame(this);
    if (gameHelper == null) {
        gameHelper = new GameHelper(this, GameHelper.CLIENT_GAMES);
        gameHelper.enableDebugLog(true);
    }
    loginGPGS();

    // make a new relative layout (as per Brents tutorial) for AdMob
    RelativeLayout layout = new RelativeLayout(this);
    View gameView = initializeForView(game, config);
    gameView.setMinimumHeight(200);
    layout.addView(gameView);


    // create the new AdView and pass it this (it takes an activity but calls it context - i dunno why yet!)
    adView = new AdView(this);

    // set the adListener for the adView:
    adView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            Log.i(TAG, "ad loaded..." );
        }
    });

    // set size and Ad Id for banner ad
    adView.setAdSize(AdSize.SMART_BANNER);
    adView.setAdUnitId("ca-app-pub-9900639686681371/7970613041");

    // create an adrequest builder
    AdRequest.Builder builder = new AdRequest.Builder();
    builder.addTestDevice("42BC38E35388C24799529CF0FA59830A");
    // sets layout of advert to wrap to width and height:
    RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

    // add the banner ad to our layout with the adParams:
    layout.addView(adView, adParams);

    adView.loadAd(builder.build());



    setContentView(layout);

    gameHelper.setup(this);
    initialize(game, config);

}

@Override
public void onStart(){
    super.onStart();
    gameHelper.onStart(this);
}

@Override
public void onStop(){
    super.onStop();
    gameHelper.onStop();
}

@Override
protected void onPause() {
    adView.pause();
    super.onPause();
}

@Override
protected void onResume() {
    super.onResume();
    adView.resume();
}

@Override
public void onActivityResult(int request, int response, Intent data) {
    super.onActivityResult(request, response, data);
    gameHelper.onActivityResult(request, response, data);
}

@Override
public boolean getSignedInGPGS() {
    return gameHelper.isSignedIn();
}

@Override
public void loginGPGS() {
    try {
        runOnUiThread(new Runnable(){
            public void run() {
                gameHelper.beginUserInitiatedSignIn();
            }
        });
    } catch (final Exception ex) {
    }

}

@Override
public void submitScoreGPGS(int score) {
    Games.Leaderboards.submitScore(gameHelper.getApiClient(), getString(R.string.leaderboard_top_scorers_world), score);
}

@Override
public void unlockAchievementGPGS(String achievementId) {
    Games.Achievements.unlock(gameHelper.getApiClient(), achievementId);
}

@Override
public void getLeaderboardGPGS() {
    if (gameHelper.isSignedIn()) {
        startActivityForResult(Games.Leaderboards.getLeaderboardIntent(gameHelper.getApiClient(), getString(R.string.leaderboard_top_scorers_world)), 100);
    }
    else if (!gameHelper.isConnecting()) {
        loginGPGS();
    }
}

@Override
public void getAchievementsGPGS() {
    if (gameHelper.isSignedIn()) {
        startActivityForResult(Games.Achievements.getAchievementsIntent(gameHelper.getApiClient()), 101);
    }
    else if (!gameHelper.isConnecting()) {
        loginGPGS();
    }
}

@Override
public void onShowAchievementsRequested() {

}

@Override
public void onSignInFailed() {

}

@Override
public void onSignInSucceeded() {

}

}

\$\endgroup\$
1
\$\begingroup\$

ok i actually found the answer. I had to move my initialize(game, config); call in AndroidLauncher to be BEFORE the call setContentView(layout);

\$\endgroup\$
  • \$\begingroup\$ you can accept your own answer by clicking on the checkmark \$\endgroup\$ – Benedikt S. Vogler May 21 '17 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.