[英]My HTML5 Game based phonegap not support again for admob
我已經用Android的phonegap創建了我的第一個HTML5游戲。 當我添加Google Play服務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腳本,則我的游戲可以正常運行。 希望任何人都能幫助我快速解決此問題
更新(3/3/2014)
在模擬器上運行時,其我的logcat pastebin包含錯誤消息
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" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.