AdView在Android Studio中无法识别

时间:2016-08-29 08:11:24

标签: android admob adview

我正在尝试将Admob集成到我的应用中,但Android Studio无法找到这些库:

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

这是我的顶级格斗:

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.1.2'
    classpath 'com.google.gms:google-services:3.0.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    jcenter()
}
}

这个项目级别的gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.1"

defaultConfig {
    applicationId "com.tomhogenkamp.personalcalc"
    minSdkVersion 16
    targetSdkVersion 24
    versionCode 4
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.github.yukuku:ambilwarna:2.0.1'
}

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

我在更多应用中添加了Admob,但我没有遇到任何麻烦。

任何人都可以帮助我吗?

谢谢!

3 个答案:

答案 0 :(得分:1)

您似乎错过了广告的依赖关系。你的build.gradle:

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.android.support:appcompat-v7:24.1.1'
  compile 'com.google.firebase:firebase-core:9.4.0'
  compile 'com.github.yukuku:ambilwarna:2.0.1'
}

应该有一个额外的一行:

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.android.support:appcompat-v7:24.1.1'
  compile 'com.google.firebase:firebase-core:9.4.0'
  compile 'com.google.firebase:firebase-ads:9.4.0'
  compile 'com.github.yukuku:ambilwarna:2.0.1'
}

有关详细信息,我们最近撰写了一篇关于使用Firebase导入移动广告SDK的方法的blog post。还有一个episode移动广告车库可以解决此问题。

答案 1 :(得分:0)

打开SDK管理器 - >额外 - >安装Google存储库& Google Play服务

如果您已经更新了这些,请分享显示确切错误的错误日志

答案 2 :(得分:0)

确保正确安装了Google Play服务

打开SDK管理器并安装Google Play服务。

然后将此行添加到Gradle(模块)

compile 'com.google.android.gms:play-services:9.4.0'