【问题标题】:AdMob: Missing required XML attribute adUnitIDAdMob:缺少必需的 XML 属性 adUnitID
【发布时间】:2011-04-10 17:12:51
【问题描述】:

我是广告方面的新手,我无法让它发挥作用。 我已经完成了http://code.google.com/intl/nl-NL/mobile/ads/docs/android/banner_xml.html 中所述的操作。

这是我的 main.xml:

<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="com.niek.runningapp"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#FFFFFF"
    android:stretchColumns="1">
<!-- more stuff-->
    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <com.google.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adUnitId="a14da18492dd1f0"
            ads:adSize="BANNER" />
    </TableRow>
<!-- More stuff -->

这是我在 res/values 中的 attrs.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <declare-styleable name="com.google.ads.AdView">
      <attr name="adSize">
          <enum name="BANNER" value="1"/>
          <enum name="IAB_MRECT" value="2"/>
          <enum name="IAB_BANNER" value="3"/>
          <enum name="IAB_LEADERBOARD" value="4"/>
      </attr>
      <attr name="adUnitId" format="string"/>
  </declare-styleable>
</resources>

运行应用时出现以下错误:

XML 布局中的 adSize 参数无效:-1。默认为横幅

AdView 缺少必需的 XML 属性 adUnitId。

我做错了什么?

【问题讨论】:

  • 感谢分享问题所在。我遇到了同样的问题,这对我有帮助。
  • Niek 您能否将您的修复添加为下面的答案并标记为已回答,以帮助其他人搜索和找到此问题。谢谢
  • Devs,如果您在 xmlns:ads 中使用您的项目包,那么您还需要按照 James here 的说明添加“attrs.xml”。对于较新的 Admob sdk,不再推荐使用 attrs.xml。只需使用以下命名空间:xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

标签: android admob identifier


【解决方案1】:

还在纠结的朋友可以试试xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

【讨论】:

    【解决方案2】:

    根据最新的 SDK ,应该如下:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多