android - com.google.android.gms.ads.AdView 找不到 Android Studio

标签 android android-studio admob google-play-services

为了解决这个问题,我研究了好几天。与 Google Play 服务有关的任何内容都标为红色。 它在 Gradle 中已经是最新版本 我已经把网站上说的所有东西都放在那里了,但它仍然是红色的。

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

最佳答案

您是否事先添加了 SDK 工具?
继续SDK管理器 > 其他> 选择 Google 存储库Google Play 服务并安装它们。


有关更多详细信息,请阅读此 document.

关于android - com.google.android.gms.ads.AdView 找不到 Android Studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32657422/

相关文章:

android - 设置页面底部的 AdMob 横幅

php - 在 Android 中使用 PHP 和 MySQL 检测互联网并保存到内部存储

java - 在运行之前访问Runnable的方法

java - 文件目录 res/raw 在哪里?

android - 在多个 Android 应用程序中使用相同的 admob 发布者 ID(广告单元 ID)?

android - Admob 广告在模拟器中显示,但在 Admob 帐户中没有状态

android - 如何在 Android 中使用辅助功能服务删除缓存?

android - Quickblox:阻止用户创建帐户

AndroidAnnotations 没有生成,空 Activity

android - 小部件类型旁边的字母数字是什么?