Breaking

Wednesday 10 July 2019

error: Can't resolve symbol 'AdRequest' and 'AdView'


error: Can't resolve symbol 'AdRequest' and 'AdView'


dependencies {
        .......
        compile 'com.google.firebase:firebase-ads:9.6.0'
    }

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

Verified app-level build.gradle

<string name="banner_ad_unit_id">ca-app-pub-MY_ID</string>

added my ad unit ID to strings.xml

 

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

placed my ad to relative layout also added xmlns:ads="http://schemas.android.com/apk/res-auto" to my relativelayout


In MainActivity.java


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

import com.google.android.gms.ads.AdView;
 
public class MainActivity extends ActionBarActivity {
 
...
 
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
 
    MobileAds.initialize(getApplicationContext(), "ca-app-pub-MY_ID");
 
    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
}

Eventhough, I've imported import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdView; still getting cannot resolve AdRequest and AdView errors.

I also tried clean project and download gradles again.


ANS :- 2



Go to File > Project StructureAds > and enable the check box shown in Admob . click on Okbutton Its worked for me.


ANS :- 3



Change the version number of play-services-ads on your gradle to the same version number on your Ads setting page (File->Project Structure->Ads). By this way my android studio finally resolves


No comments:

Post a Comment