错误膨胀类 com.google.android.gms.ads.AdView Android Studio [英] Error inflating class 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);
在依赖项中:
我做错了什么??????
what i'm doing wrong????
推荐答案
包含 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 文件,最好不要将它们放在构建文件夹中——如果您进行干净的构建,它可能会被删除.最好的位置是在模块根目录的 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屋!