There are so question like that but it's not duplicate
because i have already used xmlns:ads="http://schemas.android.com/apk/res-auto"
and i have done code mostly in java
I want to use google play service for ads
I have used below java code
com.google.android.gms.ads.AdView adView = (com.google.android.gms.ads.AdView) activity.findViewById(R.id.adview);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(activity.getString(R.string.admob_id));
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
and following xml code
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
but i am getting error in banner is like
Requred XML attribute 'adsize' was missing
Change the namespace to
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
Ad.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.gms.ads.AdView
android:id="@+id/adview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER" />
</LinearLayout>
NOTE :
Use this Namespace for new SDK
xmlns:ads="http://schemas.android.com/apk/res-auto"
Try add "ads:adSize" to XML like below:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adview"
ads:adSize="SMART_BANNER"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
Remove "adView.setAdSize(AdSize.SMART_BANNER);" from your java file.
Refer below:
Here is the XML layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="INSERT_YOUR_AD_UNIT_ID_HERE"/>
</LinearLayout>
And here is your java file
package com.google.example.gms.ads.xml;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import android.app.Activity;
import android.os.Bundle;
/**
* A simple {@link Activity} which embeds an AdView in its layout XML.
*/
public class BannerXMLSample extends Activity {
private static final String TEST_DEVICE_ID = "INSERT_YOUR_TEST_DEVICE_ID_HERE";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// The "loadAdOnCreate" and "testDevices" XML attributes no longer available.
AdView adView = (AdView) this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice(TEST_DEVICE_ID)
.build();
adView.loadAd(adRequest);
}
}
Refer the example here
https://github.com/googleads/googleads-mobile-android-examples/tree/master/admob/banner-xml