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

萝らか妹 提交于 2019-12-25 02:37:31

问题


I am trying to integrate admob ads in my application but I am getting this error.

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

Main XML Layout Code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="@drawable/background" >

    <com.google.ads.AdView 
    android:id="@+id/ad"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"    
    ads:adUnitId="My_Add_Id"
    ads:loadAdOnCreate="true" />

Mainifest file is as follows:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.solutionproviders.bajiascooking"
    android:versionCode="1"
    android:versionName="1.0" >

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


    <uses-sdk android:targetSdkVersion="16" 
              android:minSdkVersion="9"/>


    <application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name=".Main"
            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.ads.AdActivity"
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

    </application>

</manifest>

I am using Google play services for adding ads.

I am checked all the solutions provided on Stakeoverflow but none worked for me. Please suggest me a solution. Any other info will be provided but I think I have provided enough info for the problem.


回答1:


Since you're using the Google Play Services you have to change the class from

com.google.ads.AdView

to

com.google.android.gms.ads.AdView

Do not use the AdMob SDK - this one is deprecated as of August 1st. You won't be able to publish an *.apk in the Play Store if you're using this outdated SDK. Admob is now part of the Google Play Services and it's mandatory to use this one. Read more in the Docs (Google Mobile Ads SDK).




回答2:


Just follow these 3 steps:

  1. add a dependency in gradle app level.
  2. add xml in the yourfile.xml
  3. java code in onCreate Method

Dependency : implementation 'com.google.android.gms:play-services-ads:11.8.0'



来源:https://stackoverflow.com/questions/25604618/com-google-ads-adview-the-following-classes-could-not-be-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!