Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve symbol 'MobileAds'

Ok, so I'm working on an android app and I'm trying to put ads in it, but I get the error "Cannot resolve symbol 'MobileAds'" whenever I try to compile it.

Here's what I have:

activity_main.java
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

public class MainActivity extends ListActivity {
private ArrayList<Sound> mSounds = null;
private SoundAdapter mAdapter = null;
static MediaPlayer mMediaPlayer = null;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    MobileAds.initialize(getApplicationContext(), "ca-app-pub-Removed");

    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
}

My XML:

xmlns:ads="http://schemas.android.com/apk/res-auto"  
<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>

And

<string name="banner_ad_unit_id">ca-app-pub-(removed)</string>

Project Gradle

 dependencies {
    classpath 'com.android.tools.build:gradle:2.2.0'
    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
}

App Gradle

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.firebase:firebase-ads:9.6.0'
testCompile 'junit:junit:4.12'


 }
 apply plugin: 'com.google.gms.google-services'

Why am I getting this error message? any help on this is appreciated. Thanks!

like image 912
Freeman Avatar asked Sep 27 '16 03:09

Freeman


2 Answers

For anyone having this problem:

Make sure that you have

import com.google.android.gms.ads.MobileAds;

in your MainActivity.java

like image 109
Freeman Avatar answered Oct 20 '22 14:10

Freeman


First of all make sure you already all the steps of Google AdMob Get started,

https://developers.google.com/admob/android/quick-start

then go to the Android Studio > Tools > SDK manager > SDK Tools and check you have installed Google play services & Google Repositoryenter image description here

if not installed it and then go to the Android studio > File > Sync Project with gradle file

like image 20
Pinkesh Panchal Avatar answered Oct 20 '22 12:10

Pinkesh Panchal