AdMob无法加载基于Java的游戏应用程序

时间:2016-09-26 15:54:23

标签: java android admob

所以我一直在努力解决这个问题。我正在尝试在Android游戏应用中加载AdMob横幅广告。我按照教程来谚语,我一直得到这个错误:

W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
W/Ads: There was a problem getting an ad response. ErrorCode: 0
W/Ads: Failed to load ad: 0

我已经确认该项目中包含最新版本的Play服务(9.6.0)。我的Firebase是最新的,我在我的gradle中包含了核心,身份验证和广告库。我还在Firebase中定义了身份验证方法。我的代码如下:

public class MainActivity extends BaseGameActivity {
    PApplet fragment;
    private static final String MAIN_FRAGMENT_TAG = "main_fragment";
    private static final int REQUEST_PERMISSIONS = 1;
    private AdView adView;
    int viewId = 0x1000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);

        Window window = getWindow();
        window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        FrameLayout frame = new FrameLayout(this);
        frame.setId(View.generateViewId());

        if (savedInstanceState == null) {
            fragment = new box_jump();
            FragmentTransaction ft = getFragmentManager().beginTransaction();
            ft.add(frame.getId(), fragment, MAIN_FRAGMENT_TAG).commit();
        } else {
            fragment = (PApplet) getFragmentManager().findFragmentByTag(MAIN_FRAGMENT_TAG);
        }
        MobileAds.initialize(getApplicationContext(), "ca-app-pub-2885131178882767~7287529334");


        adView = new AdView(this);
        adView.setAdUnitId("ca-app-pub-2885131178882767/3137714538");
        adView.setAdSize(AdSize.SMART_BANNER);

        RelativeLayout mainLayout = new RelativeLayout(this);
        mainLayout.addView(frame);

        RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        mainLayout.addView(adView, adParams);

        setContentView(mainLayout);
    }

    public void showAd() {
        adView.setVisibility(View.VISIBLE);
        adView.loadAd(new AdRequest.Builder().addTestDevice("4B8A8368A73BDA47066700EA90CB50DB").build());
    }
    public void hideAd() {
        adView.setVisibility(View.GONE);
    }
}

我非常感谢所有帮助,并且很乐意验证您可能需要的任何信息。

1 个答案:

答案 0 :(得分:0)

好的,所以我发现了问题。它实际上非常简单,我正在测试的手机上有AdAway,即使我卸载了它,我也没有事先禁用它。此外,我运行应用程序的模拟器没有安装Google Play服务。整顿两者导致广告正常运作。