Werner
Werner

Reputation: 769

android - google play services ads - The following classes could not be instantiated: com.google.android.gms.ads.AdView

I just clean installed Android Development Tools (ADT) and I am having trouble getting Google Play Services to work properly; more specifically, I can't get the layout preview to instantiate an adView BANNER.

Imported the latest GPS library into my workspace (copied to workspace from the sdk/extras/Google/google-play-services)

Right-clicked project > properties > android tab > added GPS library to project

Added the following to my project's manifest:

Outside <application>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Inside <application>

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

Minium sdk set to "9"

Target "21"

In my layout file:

<RelativeLayout 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"
tools:context="${relativePackage}.${activityClass}" >


<com.google.android.gms.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="my ad id as stated on apps.admob.com"
                     ads:adSize="BANNER"/>

In the Graphical Layout pane, I get the error

The following classes could not be instantiated:
- com.google.android.gms.ads.AdView

Am I forgetting something? Did I make an error somewhere? Anyone have any ideas on how to fix this>

Thanks!

Upvotes: 0

Views: 248

Answers (1)

Gail
Gail

Reputation: 316

This is a temporary work-around for me. I downgraded the version of Google Play Services SDK from 5.x back to 4.x. I use Intellij Community 13.x with Gradle so my dependency section looks like this now:

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

Again, just temporary to allow me to finish building my XML layout files. I plan to upgrade to the latest version 5.x when I enter my final testing phase. I have filed issues about this problem with the Google AdMob Ads Developers forum in hopes of getting someone's attention. I have not found a way to file a bug report for this specific SDK but I'm still looking.

Upvotes: 1

Related Questions