【问题标题】:com.google.android.gms.ads.AdView could not be found Android Studiocom.google.android.gms.ads.AdView 找不到 Android Studio
【发布时间】:2015-09-18 17:02:50
【问题描述】:

我已经研究了好几天,试图弄清楚这一点。任何与 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,请尝试清理项目(构建 -> 清理项目)。

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


【解决方案1】:

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


更多详情,请阅读document.

【讨论】:

  • 是的,我事先已经这样做了,我在发布帮助之前卸载/重新安装了。
  • 您的 logcat 或事件日志报告什么?
  • 我可以在“SDK Tools”而不是“Extras”上找到它
【解决方案2】:

在 android studio 中转到首选项(在 Mac 中) - 编辑器 - 常规 - 自动导入

选中即时添加明确的导入

如图所示勾选Auto Import

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-24
    • 2015-07-22
    • 2015-03-09
    • 1970-01-01
    相关资源
    最近更新 更多