The ad size and ad unit ID must be set before loadAd when set programmatically

前端 未结 7 1726
有刺的猬
有刺的猬 2020-12-14 00:01

I have no idea what is going on here but I am trying to set my ad unit ID dynamically through code like below and removing it from the XML but still get the error:

7条回答
  •  暖寄归人
    2020-12-14 00:49

    After trying,

    1. Supply adunit ID and adsize from xml ONLY.
    2. Supply adunit ID and adsize from .java file ONLY.

    Problem is solved by

    1. Removing xmlns:ads="http://schemas.android.com/apk/res-auto" line from root layout.
    2. supply adunit ID and adsize as follows,

      app:adSize="SMART_BANNER" app:adUnitId="@string/banner_ad_unit_id"

      1. Clean and run app.

提交回复
热议问题