Zanzi
Zanzi

Reputation: 57

com.google.android.gms.ads.AdView could not be found Android Studio

I've been researching for days trying to figure this out. Anything to do with Google Play Services is colored red. It's in the Gradle already the most up-to-date version I've got all the pieces the websites says to put there and it's still red.

import android.widget.Button;
import android.widget.Toast;
import com.example.zanziv.rickandmorty.R;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import java.io.IOException;

 public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



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

dependencies

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.google.android.gms:play-services:7.8.0'
compile 'com.google.android.gms:play-services-ads:7.8.0'

xml

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

Upvotes: 5

Views: 16123

Answers (2)

Md.Tahmid Bin Rashid
Md.Tahmid Bin Rashid

Reputation: 51

In android studio Go to Preference(In Mac) - Editor - General - Auto Import

Check Add unambigious imports on the fly

Check the box as the picture shown Auto Import

Upvotes: 0

siriuseteor77
siriuseteor77

Reputation: 1126

Did you add the SDK tools beforehand?
Go on SDK Manager > Extras > Select Google Repository and Google Play services and install them.


For more details, read this document.

Upvotes: 4

Related Questions