Error Inflating Class Com.Google.Ads.Adview

Error inflating class com.google.android.gms.ads.AdView in android studio

You are using very old version of ads sdk.Change it with the latest.

implementation 'com.google.android.gms:play-services-ads:19.1.0'
Also you have to add meta data in your manifest file's application tags

<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>

You can try like this

<com.google.android.gms.ads.AdView

android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id"/>

Error inflating class com.google.android.gms.ads.Adview (Android Studio)

I solved the error by copying my application files to a BannerExample project from Google. To make my app shows the ads, I changed specially the following files.

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="br.com.nlpoomanual" >

<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="23"
>
</uses-sdk>

<!-- Include required permissions for Google Mobile Ads to run-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
android:allowBackup="true"
android:icon="@drawable/ic_afrogirl"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!--This meta-data tag is required to use Google Play Services.-->
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
<activity
android:name=".activity.TelaInicial"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.android.gms.example.bannerexample.MyActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.SobreActivity"
android:label="@string/sobre_titulo" >
</activity>
<activity
android:name=".activity.AjudeNosActivity"
android:label="@string/title_activity_ajude_nos" >
</activity>
<activity
android:name=".activity.DicionarioDeTermos"
android:label="@string/title_activity_dicionario_de_termos" >
</activity>
<activity android:name=".activity.DescricaoTermoActivity"
android:label="@string/dicionario"
>
</activity>
<activity android:name=".activity.BuscaComponentesActivity"
android:label="@string/busca_componentes">
</activity>
<activity android:name=".activity.TipoProdutoActivity"
android:label="@string/produtos_liberados"
>
</activity>
<activity android:name=".activity.BuscaProdutosActivity"
android:label="@string/produtos_liberados"
>
</activity>
<activity android:name=".activity.DescricaoProdutoActivity"
android:label="@string/produtos_liberados"
>
</activity>
<activity android:name=".activity.MenuPrincipalActivity"
android:label="@string/app_name">
</activity>
<activity
android:name=".activity.FotoProdutoActivity"
android:label="@string/produtos_liberados"
>
</activity>
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
</application>

</manifest>

ajude_nos.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activity.AjudeNosActivity"
tools:ignore="MergeRootFrame"
>

<ScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>

<com.google.android.gms.ads.AdView
android:id="@+id/ajudeNosAdView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-7700319823577941/5947568710" />

<TextView
android:id="@+id/desc_ajude_nos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/texto_comum"
android:text="@string/desc_ajude_nos"
android:layout_margin="15dp"
/>

<RadioGroup
android:id="@+id/rg_ajude_nos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/pink"
>
<RadioButton
android:id="@+id/rb_sugestao_produto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/rb_sugestao_produto"
android:onClick="onRadioButtonClicked"
android:checked="true"
android:background="@color/background_white"
android:layout_marginBottom="7dp"
android:layout_marginTop="7dp"
/>
<RadioButton
android:id="@+id/rb_sugestao_componente"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/rb_sugestao_componente"
android:onClick="onRadioButtonClicked"
android:background="@color/background_white"
android:layout_marginBottom="7dp"
/>
<RadioButton
android:id="@+id/rb_sugestao_termo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/rb_sugestao_termo"
android:onClick="onRadioButtonClicked"
android:background="@color/background_white"
android:layout_marginBottom="7dp"
/>
<RadioButton
android:id="@+id/rb_comunique_erro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/rb_comunique_erro"
android:onClick="onRadioButtonClicked"
android:background="@color/background_white"
android:layout_marginBottom="7dp"
/>

<RadioButton
android:id="@+id/rb_outros"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/rb_outros"
android:onClick="onRadioButtonClicked"
android:background="@color/background_white"
android:layout_marginBottom="7dp"
/>

</RadioGroup>

<Button
android:id="@+id/bt_proximo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bt_proximo"
android:layout_gravity="center"
android:layout_margin="20dp"
android:onClick="onButtonClicked"
android:background="@color/pink"
android:textColor="@color/background_white"
/>

</LinearLayout>
</ScrollView>

</LinearLayout>

build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
applicationId "com.google.android.gms.example.bannerexample"
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.google.android.gms:play-services-ads:8.1.0'
}

Error inflating class com.google.ads.AdView

Have you recently updated your Android Tools to r17 or higher? If so, you need to create a libs/ folder in your project, and physically put the SDK in the project. Or, in the Java Build Path, you must Order and Export the SDK jar.

Otherwise, the jar doesn't get included when your apk gets compiled, and all hell breaks loose when you run AdMob code at runtime.

NOTE: This applies to any library your project references.

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

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.



Related Topics



Leave a reply



Submit