在从旧的AdMob迁移时,在布局XML中创建新的AdView时遇到了一个非常奇怪的问题。
好的。产品目标-谷歌API 19默认属性-谷歌API 8
googleplaylib在项目中被引用,并且似乎被索引,然后被包含在生成的apk中(证据如下)。
我的布局中有以下代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.android.gms.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0"
android:orientation="vertical" >
...
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
ads:adSize="BANNER"
ads:adUnitId="@string/admob_unit_id"
/>
当我加载布局时,我得到了异常。
我看到了以下可疑的东西:
我特别把使用AdView的代码放在XML加载之前,也不例外
com.google.android.gms.ads.AdView ad= new com.google.android.gms.ads.AdView(this); try { setContentView(R.layout.ap_map); } catch(RuntimeException e) { throw e; }
所以,我认为谷歌播放库本身没有问题。然而,当我调试异常时——我有一个内部异常——NoClassDefFoundException,所以它看起来就像我在谷歌播放库中错过了
我对AdView声明有奇怪的问题-如果我按照谷歌建议的声明
我有一个错误,说
- error: No resource identifier found for attribute 'adSize' in package MYPACKAGE
所以我不得不添加
xmlns:ads="http://schemas.android.com/apk/lib/com.google.android.gms.ads"
在布局声明的顶部去掉这个
有什么想法吗?我在这里读到了一些相关的主题,所有这些主题似乎都与谷歌播放库的缺失有关,但
更改:
xmlns:ads="http://schemas.android.com/apk/lib/com.google.android.gms.ads"
至:
xmlns:ads="http://schemas.android.com/apk/res-auto"