Required XML attribute “adSize” was missing

匿名 (未验证) 提交于 2019-12-03 01:14:02

问题:

I get a "Required XML attribute "adSize" was missing" when I launch my app. This is written on the screen of my smartphone instead of my banner.

I tried the different solutions founded on stack (like xmlns:ads="http://schemas.android.com/apk/res-auto" instead of xmlns:ads="http://schemas.android.com/apk/libs/com.google.ads" or instead of xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads") but it doesn't work.

Here's my java code (a simple Hello World just to try to implement a banner):

package com.example.publicite;  import android.os.Bundle; import android.app.Activity; import android.view.Menu;  public class MainActivity extends Activity {  @Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_main); }  @Override public boolean onCreateOptionsMenu(Menu menu) {     // Inflate the menu; this adds items to the action bar if it is present.     getMenuInflater().inflate(R.menu.main, menu);     return true; } }

Here's my xml file:

 

and here's my manifest:

I use the google play service lib.

回答1:

Here is a weird answer. I just restarted my eclipse and it stared working. This might help some one.

Just restart eclipse or android studio



回答2:

Try changing your declaration this way:

---- EDIT ----

You can also try to do it programmatically. Simply, instead of an AdView layout item, define a LinearLayout and by code do something like this:

final AdView adView = new AdView(getActivity()); adView.setAdUnitId("YourId"); adView.setAdSize(AdSize.BANNER);  final LinearLayout adLinLay = (LinearLayout) view.findViewById(R.id.your_defined_linearlayout); adLinLay.addView(adView);  final AdRequest.Builder adReq = new AdRequest.Builder(); final AdRequest adRequest = adReq.build(); adView.loadAd(adRequest);


回答3:

I had the same problem and I corrected it with the xmlns labels. I put two "xmlns:ads" labels (one for "res-auto" in the AdView and other for "tools" in the parent layout). I had to use two labels for "res auto", one with xmlns:app in the FloatingActionButton and other with xmlns:ads in the AdView:



回答4:

change as below ..remove ads:loadAdOnCreate="true"

   

check this link, it has clear example

https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals#play



回答5:

This happen when eclipse failed to syncronize your xml with google play library, try cleaning project and restart eclipse



回答6:

I have same problem.

Solution for me:

 xmlns:ads=""

changed to

xmlns:ads="http://schemas.android.com/apk/res-auto"


回答7:

Juste clean your app !

Build -> Clean Project

The message dissapear.



回答8:

add this in android manifest :

android:theme="@android:style/Theme.Translucent"

it solve my problem, i hope it will solve yours :)



回答9:

It turns out that you CANNOT use wrap_content as a size, so you need to give it a size instead. My ads weren't working and after a day of googling I changed my

android:layout_height="wrap_content"

to

android:layout_height="100dp"

and it fixed the issue. P.S. "match_parent" does work (I have that set for my width)



回答10:

Check for DEIVCE_ID_EMULATOR too as in my code I have the following code from following the tutorial from Google:

AdRequest adRequest = new AdRequest.Builder()      .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)      .build();

In my case I was testing it on a real device so it never came up but just gave me the message that the adsize was not set. I ran up an emulator and nkn's solution works perfectly.

Here is my complete code: In main activity:

AdView adView = (AdView)findViewById(R.id.adView); AdRequest adRequest = newAdRequest.Builder()      .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)      .build(); adView.loadAd(adRequest);

and my XML:

NOW run the app on your device and check out your logcat as it will show the line: I/Ads: Use

AdRequest.Builder.addTestDevice("33BE2250B43518CCDA7DE426D04EE232") to get test ads on this device.

Copy this id (DIFFERENT FOR YOUR DEVICE) to the .addTestDevice as follows:

AdView adView = (AdView)findViewById(R.id.adView);     AdRequest adRequest = newAdRequest.Builder()          .addTestDevice("33BE2250B43518CCDA7DE426D04EE232")          .build();     adView.loadAd(adRequest);

AND That is how I fixed this issue in my case.

Hope it helps.



回答11:



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!