简体   繁体   中英

App crashing after AdMob addition, how can I make it run?

I am pretty new in Android Studio. I am trying to add Admob to my app. I have completed all the steps at Admob website except for the first one. My project build.gradle is as follows:

plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
}

So I just can't add allprojects and buildscript parts, it is giving me errors.And as soon as I implement this

dependencies {  implementation 'com.google.android.gms:play-services-ads:21.4.0'}

into module, the app is crashing upon running. Other than the buildscript and allproject parts, everyting is correct as it was told at admob page. Please help me.

I have tried adding admob banner.

your problem is not quite clear where you are experiencing the problem exactly, but my assumptions go to either you did not add the Ads APP ID correctly or at all in the project, or did not use proper ads ids.

Other possibilities may be you did not add the dependencies correctly which is what I assume by looking at code you provided.

Most documentations are using old looks of gradle file, which has updated to be now as the one you have showed, however you can still add the old style.

So, in order to add the Google Services dependency/plugin in the project build gradle you can do it as follow and end up with something like this:

this is the part you need to copy and paste:

    buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:4.3.14'
    }
}

whole file would look like this:

buildscript {
dependencies {
    classpath 'com.google.gms:google-services:4.3.14'
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
 id 'com.android.application' version '7.2.2' apply false
 id 'com.android.library' version '7.2.2' apply false
}
task clean(type: Delete) {
 delete rootProject.buildDir
}

Note: these are on Project level gradle file

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