膨胀类 com.google.android.gms.ads.AdView Android Studio 时出错 [英] Error inflating class com.google.android.gms.ads.AdView Android Studio

查看:44
本文介绍了膨胀类 com.google.android.gms.ads.AdView Android Studio 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要疯了.

我正在尝试使用 google play 服务更改 admob.但我被这个错误困住了.

I'm trying to change admob using google play services. But i'm stuck on this error.

Caused by: android.view.InflateException: Binary XML file line #53: Error inflating class com.google.android.gms.ads.AdView

我有这个:

<com.google.android.gms.ads.AdView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="5dp"
    android:id="@+id/adViewPers"/>

还有这个:

<meta-data android:name="com.google.android.gms.version"
               android:value="@integer/google_play_services_version"/>
<activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

主要活动

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;

...
private AdView adViewPers;

...

adViewPers = (AdView) findViewById(R.id.adViewPers);
adViewPers.setAdUnitId("xxxxxxx");
adViewPers.setAdSize(AdSize.SMART_BANNER);
AdRequest adRequest = new AdRequest.Builder().build();
adViewPers.loadAd(adRequest);

并在依赖项中:

我做错了什么????

推荐答案

包含 Google Play 服务的更好方法是通过项目结构"对话框中的库依赖项——而不是像您所做的那样添加 jar 文件,单击+ 按钮 > 库依赖项.Google Play 服务应该在列表中.

The better way to include Google Play Services is via a Library dependency in the Project Structure dialog -- instead of adding the jar file as you have done, click the + button > Library dependency. Google Play Services should be in the list.

另外,如果您要添加 jar 文件,最好不要将它们放在 build 文件夹中——如果您进行干净的构建,它可能会被删除.最好的位置是模块根目录下的 libs 目录.

Also, if you're adding jar files, it's really best to not put them in the build folder -- that can get erased if you do a clean build. The best place is in a libs directory at your module root.

这篇关于膨胀类 com.google.android.gms.ads.AdView Android Studio 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆