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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With