Alex
Alex

Reputation: 63

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

I get this error:

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

I have updated Google Play Services to Version 37 and Google Repository to Version 38.

Also in my MainActivity class in my OnCreate() method, I get Cannot resolve symbol 'MobileAds' error. I know it is caused by a missing an import, but I am not offered a class to import.

MobileAds.initialize(getApplicationContext(), "ca-app-pub-3940256099942544~3347511713");

XML file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.example.gateway.myapp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp"
    tools:context="com.example.gateway.myapp.Class"
    android:orientation="vertical">
    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id">
    </com.google.android.gms.ads.AdView>
</LinearLayout>

build.gradle (Module):

apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.example.gateway.myapp"
        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'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.google.firebase:firebase-core:9.8.0'
}
apply plugin: 'com.google.gms.google-services'

build.gradle (Project):

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        classpath 'com.google.gms:google-services:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Upvotes: 1

Views: 872

Answers (2)

Sasi Kumar
Sasi Kumar

Reputation: 13358

In your gradle file add com.google.firebase:firebase-ads

dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])

        compile 'com.google.firebase:firebase-ads:9.8.0'
    }

google updated(including Firebase and SDK) Mobile Ads in Google Mobile Ads SDK

Upvotes: 1

QuokMoon
QuokMoon

Reputation: 4425

Admobs now a part of Firebase SDK and Google Mobile Ads delivered by Google play services.It is no longer available in standalone SDK.

Reference link and Migrate from the Google project.

Upvotes: 0

Related Questions