2014-09-04 104 views
0

我試圖在自己的應用上放置廣告,但由於某種原因,廣告橫幅無效,因爲插頁式廣告的確有效,所以這是有線的。Android AdMob Banner無法正常工作

這裏是我的xml:

<com.google.android.gms.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/textView1" 
     android:layout_alignLeft="@+id/fartDisplay" 
     ads:adSize="BANNER" 
     ads:adUnitId="My-Ad-Unit-Id" > 
    </com.google.android.gms.ads.AdView> 

,這裏是我的Java代碼:

private AdView mAdView; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 

     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.activity_fart); 

     mAdView = (AdView) findViewById(R.id.adView); 
     mAdView.loadAd(new AdRequest.Builder().build()); 
    } 

IM也對logcat的得到這個:

09-04 19:34:54.919: E/GooglePlayServicesUtil(2841): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included. 
09-04 19:34:54.929: E/GooglePlayServicesUtil(2841): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included. 

回答

0

確保您有以下在依賴關係中的build.gradle文件中。

compile 'com.google.android.gms:play-services:5.2.08' 

還必須添加以下的manifest.xml文件

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

我在這裏看到的另一個問題是廣告:adUnitId設置=「我-廣告單元ID」 你必須在strings.xml文件中添加您的廣告單元ID,並將字符串值放在標記中,如下所示: ads:adUnitId =「@ string/My-Ad-Unit-Id」

+0

我有元數據,而我改變單位ID爲字符串,所以它不會是可見的,即時通訊使用Eclipse,Gradle只在android工作室沒有? – Pachu 2014-09-04 16:57:28

+0

對Eclipse IDE執行以下步驟https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start – Psypher 2014-09-04 18:11:15