android studio无法解析adView类

时间:2016-12-17 10:51:10

标签: android admob

我正在尝试整合admob奖励视频广告。我有空白项目。我也根据this spec集成了firebase sdk。但是当我输入AdView类android studio并没有#39} ;看到它.Package com.google.android.gms.ads不包含AdRequestMobileAds等广告类。我的gradle文件:

根:

   // Top-level build file where you can add configuration options common to all sub-projects/modules.

   buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'
    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()
}
}

task clean(type: Delete) {
       delete rootProject.buildDir
}

应用级别:

apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
    applicationId "com.rhyboo.net.rewarded_video"
    minSdkVersion 16
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

2 个答案:

答案 0 :(得分:1)

您似乎错过了指南的最后一步,即为Firebase添加库以及您正在使用的各个服务。

只需添加以下行:

compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-ads:10.0.1'

到你的build.gradle依赖项:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.google.firebase:firebase-core:10.0.1' // new!
    compile 'com.google.firebase:firebase-ads:10.0.1'  // new!
    testCompile 'junit:junit:4.12'
}

这是使用Firebase导入AdMob的正确方法。您可以查看this video了解演练。

答案 1 :(得分:0)

忘了将compile 'com.google.android.gms:play-services:10.0.1'添加到应用级依赖关系块