我的基于HTML5游戏的phonegap不再支持admob

时间:2014-02-27 05:55:13

标签: java android html5 cordova admob

我已经用android的phonegap创建了我的第一个HTML5游戏。当我添加Google Play Service SDK以支持admob插件之后,我的游戏无法在我的设备和模拟器上启动。 您可以从MainACtivity.Java中查看我的脚本中的错误,如下所示:

   package com.company.mygame;

   import android.os.Bundle;
   import android.widget.LinearLayout;
   import com.google.android.gms.ads.AdRequest;
   import com.google.android.gms.ads.AdSize;
   import com.google.android.gms.ads.AdView;
   import com.google.android.gms.ads.AdRequest.Builder;
   import android.app.Activity;
   import org.apache.cordova.*;


    public class DerpOrigamiFish extends CordovaActivity 
    {
private static final String AD_UNIT_ID = "XXXXXX";
private AdView adView; 


@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    super.init();
    // Set by <content src="index.html" /> in config.xml

    super.loadUrl(Config.getStartUrl());
    //super.loadUrl("file:///android_asset/www/index.html");

 // Create an ad.
    adView = new AdView(this);
    adView.setAdSize(AdSize.BANNER);
    adView.setAdUnitId(AD_UNIT_ID);

    // Add the AdView to the view hierarchy. The view will have no size
    // until the ad is loaded.
    LinearLayout layout = super.root;
    layout.addView(adView);

    // Create an ad request. Check logcat output for the hashed device ID to
    // get test ads on a physical device.
    AdRequest adRequest = new AdRequest.Builder()
        .build();

    // Start loading the ad in the background.
    adView.loadAd(adRequest);

  }
@Override
public void onResume() {
  super.onResume();
  if (adView != null) {
    adView.resume();
  }
}

@Override
public void onPause() {
  if (adView != null) {
    adView.pause();
  }
  super.onPause();
}

/** Called before the activity is destroyed. */
@Override
public void onDestroy() {
  // Destroy the AdView.
  if (adView != null) {
    adView.destroy();
  }
  super.onDestroy();
}

}

如果我们从mainactivity.java中删除admob脚本,我的游戏可以正常运行。我希望有人能帮助我快速解决这个问题

更新(2014年3月3日)

在模拟器上运行时,my logcat pastebin包含错误消息

1 个答案:

答案 0 :(得分:0)

logcat非常清楚地显示了问题和解决方案:

java.lang.IllegalStateException: A required meta-data tag in your app's 
AndroidManifest.xml does not exist.  You must have the following declaration within 
the <application> element:     
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

请将此添加到您的AndroidManifest。

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />