Required XML attribute "adUnitId" was missing when using android databinding

1,488 views
Skip to first unread message

Kirtan Thakkar

unread,
Nov 2, 2016, 12:55:36 PM11/2/16
to Google Mobile Ads SDK Developers
I am currently using adView inside a layout include tag which uses the android data binding. I think it clashes with the namespace of the data binding and not setting preferences. So it gives me the error mentioned in the title.

Setting adSize and adUnitId programatically also doesn't work. If you don't set adUnitId and set it with data-binding or BindingAdapter it gives you the error mentioned here (http://stackoverflow.com/q/40374013/1820644)


If i check the values just before loadAd call, it gives me the values of adUnitId and adSize. But it doesn't load the ad and shows adUnitId was missing.

What's going on?

Thanks,
Kirtan

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Nov 2, 2016, 4:34:11 PM11/2/16
to Google Mobile Ads SDK Developers
Hi Kirtan,

Your namespace in your include_ads.xml is wrong. Instead have this -

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    >
    <data>
        <variable
            name="adId"
            type="String" />
    </data>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical">

        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="@{adID}" />
    </FrameLayout>
</layout>
You need to declare with ads prefix. Let us know if you need anything else.

Thanks,
Arjun Busani
Mobile Ads SDK Team

Kirtan Thakkar

unread,
Nov 2, 2016, 11:17:13 PM11/2/16
to Google Mobile Ads SDK Developers
Thanks Veer for reaching out.

Does that makes any difference as the value is the same "http://schemas.android.com/apk/res-auto" ?  As George Mount told it doesn't matter as the value is same: http://stackoverflow.com/a/39378786/1820644 

I have also tried changing it to ads. Still it does not work. Is there can be any issue with data-binding as it uses the same namspace for custom attributes? Setting both only programtically and removing adSize and adUnitId from the xml still shows the error. 

Can you please help?

Thanks,
Kirtan

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Nov 3, 2016, 12:32:48 PM11/3/16
to Google Mobile Ads SDK Developers
Hi Kirtan,

You still need to declare ads as a namespace in the XML to load up it's attributed form the http://****/res-auto schema for it be recognized. This is for the SDK to recognize the ads element as part of its own variable. So, you definitely need to declare the ads namespace

Also, can you share your sample app with us and we will have a look?

Thanks,
Arjun Busani
Mobile Ads SDK Team

Reply all
Reply to author
Forward
0 new messages