膨胀class com.google.android.ads.AdView时出错
从旧AdMob迁移时,在布局XML中创建新的AdView时,我遇到了一个非常奇怪的问题 嗯。 产品目标-谷歌API 19 默认属性-谷歌API 8 google play lib在项目中被引用,并且似乎被索引,然后被包含到生成的apk中(证据如下) 我的布局中有以下代码膨胀class com.google.android.ads.AdView时出错,android,admob,Android,Admob,从旧AdMob迁移时,在布局XML中创建新的AdView时,我遇到了一个非常奇怪的问题 嗯。 产品目标-谷歌API 19 默认属性-谷歌API 8 google play lib在项目中被引用,并且似乎被索引,然后被包含到生成的apk中(证据如下) 我的布局中有以下代码 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
<?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"
/>
所以,我假设google play库包含本身没有问题。
然而,当我调试异常时——我有一个内部异常——NoClassDefFoundException,所以看起来就像我遗漏了google play库一样
- error: No resource identifier found for attribute 'adSize' in package MYPACKAGE
所以我不得不补充一句
xmlns:ads="http://schemas.android.com/apk/lib/com.google.android.gms.ads"
在布局声明的顶部去掉这个
有什么想法吗?我在这里读了一些相关的话题,所有这些话题似乎都与google play lib的缺失有关,但情况似乎并非如此
xmlns:ads="http://schemas.android.com/apk/lib/com.google.android.gms.ads"
致:
我更有经验的同事找到了答案。可能会有帮助,所以我不会删除这个问题。正如我猜测的那样,这个问题与XML本身有关——正确的方法是按照google的说法添加res auto,但将google play库正确导入到工作区,然后在库列表中引用它(已知的问题也是如此)。之后,adview类将可见!
xmlns:ads="http://schemas.android.com/apk/lib/com.google.android.gms.ads"
xmlns:ads="http://schemas.android.com/apk/res-auto"