AdMobs 横幅:W/GooglePlayServicesUtil﹕Google 缺少播放服务

AdMobs Banner: W/GooglePlayServicesUtil﹕ Google Play services is missing

我使用 this 来实现我的 AdMob 横幅,但是我收到一个错误:W/GooglePlayServicesUtil﹕ Google Play 服务丢失。

我已经在 build.gradle 中添加了以下行:

compile 'com.google.android.gms:play-services-ads:8.4.0'

这是我的 onCreate() 方法:

protected void onCreate(Bundle savedInstanceState){

    super.onCreate(savedInstanceState);

    AdView adView = new AdView(this);
    adView.setAdSize(AdSize.BANNER);
    adView.setAdUnitId(testBanner);

    RelativeLayout layout = new RelativeLayout(this);
    layout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

    AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest);

    //fullscreen
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    //scale image
    Display display = getWindowManager().getDefaultDisplay();
    size = new Point();
    display.getSize(size);
    dispX = size.x;
    dispY = size.y;
    bg = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(
            getResources(), R.drawable.bg),dispX,dispY,true);
    ls = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(
            getResources(), R.drawable.losescreen),GamePanel.rescaleX(805),GamePanel.rescaleY(1105),true);
    Pb = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(
            getResources(), R.drawable.playbutton),GamePanel.rescaleX(242),GamePanel.rescaleY(242),true);

    View gamePanel = new GamePanel(this);

    RelativeLayout.LayoutParams adParams =
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                    RelativeLayout.LayoutParams.WRAP_CONTENT);
    adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

    layout.addView(gamePanel);
    layout.addView(adView, adParams);


    mInterstitialAd = new InterstitialAd(this);
    setContentView(layout);
    contextOfApplication = getApplicationContext();

}

进入 SDK 管理器并下载 Google Play Services,如果还没有,请下载 Google Play Repository

(http://jmsliu.com/2085/add-admob-with-google-play-service.html)

就是这样。 gradle 中的那一行在您安装它之前没有任何意义。要打开 SDK 管理器:

(envyandroid.com)

让我知道安装 Google Play Services 后它是否有效。如果是这样,请确保接受答案。如果您需要更多帮助,请随时向我提问!

希望对您有所帮助! :-)