Search code examples
capacitorcapacitor-plugin

Android Admob-Free set ADMob-ID in capacitor


I am not sure how to set the Admob ID for the capacitor version of the Admobp-free plugin. The readme of the package refers to config.xml / the Cordova way and config.xml is not in the cap project? (iOS works fine)

https://github.com/ratson/cordova-plugin-admob-free

I'm bit confused overall that the capacitor documentation is so sparse whether I am betting on the right horse here.

The app is currently failing with, add output

03-15 22:39:04.536 28476 28476 E AndroidRuntime: FATAL EXCEPTION: main
03-15 22:39:04.536 28476 28476 E AndroidRuntime: Process: com.my.app, PID: 28476
03-15 22:39:04.536 28476 28476 E AndroidRuntime: java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException: 
03-15 22:39:04.536 28476 28476 E AndroidRuntime: 
03-15 22:39:04.536 28476 28476 E AndroidRuntime: ******************************************************************************
03-15 22:39:04.536 28476 28476 E AndroidRuntime: * Invalid application ID. Follow instructions here: goo.gl/fQ2neu to *
03-15 22:39:04.536 28476 28476 E AndroidRuntime: * find your app ID.                                                          *
03-15 22:39:04.536 28476 28476 E AndroidRuntime: ******************************************************************************

Solution

  • There is a migration doc that helps with some of this.

    Looks like the plugin is using the config.xml to set a plist property.

    <config-file target="*-Info.plist" parent="GADApplicationIdentifier">
        <string>YOUR_IOS_ADMOB_APP_ID_AS_FOUND_IN_ADMOB</string>
    </config-file>
    

    You will need to add this property manually to the Info.plist for the iOS project.

    <key>GADApplicationIdentifier</key>
    <string>YOUR_IOS_ADMOB_APP_ID_AS_FOUND_IN_ADMOB</string>
    

    For Android, add this to your AndroidManifest.xml:

    <manifest>
        <application>
            <!-- Sample AdMob app ID: YOUR_IOS_ADMOB_APP_ID_AS_FOUND_IN_ADMOB -->
            <meta-data
                android:name="com.google.android.gms.ads.APPLICATION_ID"
                android:value="YOUR_IOS_ADMOB_APP_ID_AS_FOUND_IN_ADMOB"/>
        </application>
    </manifest>