Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error inflating class com.google.android.gms.ads.AdView Android Studio

I'm going crazy.

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

i've this:

<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"/>

and this:

<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" />

main activity

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);

and in dependencies:

enter image description here

what i'm doing wrong????

like image 559
Ilario Avatar asked Oct 31 '22 20:10

Ilario


1 Answers

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.

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.

like image 50
Scott Barta Avatar answered Nov 11 '22 02:11

Scott Barta