简体   繁体   中英

Implementation 'com.google.android.gms:play-services-ads:18.1.0'

I want to add ads to my project but when i add the line below, it doesn't work:

implementation 'com.google.android.gms:play-services-ads:18.1.0'

these are the dependencies from the build.gradle :

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.1'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.gridlayout:gridlayout:1.0.0'
    implementation 'com.google.android.gms:play-services-ads:18.1.0'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

Do you have inside top-level build.gradle file reference to the google() repo or to maven { url "https://maven.google.com" } ? Do you have some specific error inside log?

Try to create a new project and copy old project files and paste in a new one. If it should help!

It is likely, that you might not have added the Google Services Gradle Plugin to the project, as well as the google-services.json file (which can be downloaded from the Firebase console ) - and so your application fails to authenticate.

Adding the com.google.android.gms.ads.APPLICATION_ID into the AndroidManifest.xml has the same effect, because the Play Services plugin adds the values from google-services.json at build-time.

... when only using AdMob, the second option should be preferred.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM