膨胀类 com.google.android.gms.ads.AdView Android Studio 时出错

Error inflating class com.google.android.gms.ads.AdView Android Studio(膨胀类 com.google.android.gms.ads.AdView Android Studio 时出错)
本文介绍了膨胀类 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 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)