Android Admob Plugin
by cengiz-pz
https://github.com/godot-sdk-integrations/godot-admob
Android Admob Plugin
Enables AdMob functionality on Godot apps that are exported to the Android platform and allows
displaying of Admob ads.
For iOS version, visit https://github.com/cengiz-pz/godot-ios-admob-plugin .
This branch contains the latest version of the plugin, which contains breaking changes to the plugin
interface. The original version of the plugin can be found on the
Release 1.0 branch.
Prerequisites
Follow instructions on the following page to create a custom Android gradle build
Create an AdMob account at the following link:
- Google AdMob
- create an app in AdMob console
- create ad(s) for your app via the AdMob console
- if needed, create consent form(s) for your app via the AdMob console
Installation
Before installing this plugin, make sure to uninstall any previous versions of the same plugin.
If installing both Android and iOS versions of the plugin in the same project, then make sure that both versions use the same addon interface version.
There are 2 ways to install the Admob plugin into your project:
- Through the Godot Editor's AssetLib
- Manually by downloading archives from Github
Installing via AssetLib
Steps:
- search for and select the
Admobplugin in Godot Editor - click
Downloadbutton - on the installation dialog...
- keep
Change Install Foldersetting pointing to your project's root directory - keep
Ignore asset rootcheckbox checked - click
Installbutton
- keep
- enable the plugin via the
Pluginstab ofProject->Project Settings...menu, in the Godot Editor
Installing both Android and iOS versions of the plugin in the same project
When installing via AssetLib, the installer may display a warning that states "[x number of] files conflict with your project and won't be installed." You can ignore this warning since both versions use the same addon code.
Installing manually
Steps:
- download release archive from Github
- unzip the release archive
- copy to your Godot project's root directory
- enable the plugin via the
Pluginstab ofProject->Project Settings...menu, in the Godot Editor
Usage
- Add
Admobnode to your main scene and populate the ID fields of the node- Debug IDs will only be used when your Godot app is run in debug mode
- Real IDs will only be used when the
is_realfield of the node is set totrue
Signals
- register listeners for one or more of the following signals of the
Admobnode:initialization_completed(status_data: InitializationStatus)banner_ad_loaded(ad_id: String)banner_ad_failed_to_load(ad_id: String, error_data: LoadAdError)banner_ad_refreshed(ad_id: String)banner_ad_clicked(ad_id: String)banner_ad_impression(ad_id: String)banner_ad_opened(ad_id: String)banner_ad_closed(ad_id: String)interstitial_ad_loaded(ad_id: String)interstitial_ad_failed_to_load(ad_id: String, error_data: LoadAdError)interstitial_ad_refreshed(ad_id: String)interstitial_ad_impression(ad_id: String)interstitial_ad_clicked(ad_id: String)interstitial_ad_showed_full_screen_content(ad_id: String)interstitial_ad_failed_to_show_full_screen_content(ad_id: String, error_data: AdError)interstitial_ad_dismissed_full_screen_content(ad_id: String)rewarded_ad_loaded(ad_id: String)rewarded_ad_failed_to_load(ad_id: String, error_data: LoadAdError)rewarded_ad_impression(ad_id: String)rewarded_ad_clicked(ad_id: String)rewarded_ad_showed_full_screen_content(ad_id: String)rewarded_ad_failed_to_show_full_screen_content(ad_id: String, error_data: AdError)rewarded_ad_dismissed_full_screen_content(ad_id: String)rewarded_ad_user_earned_reward(ad_id: String, reward_data: RewardItem)rewarded_interstitial_ad_loaded(ad_id: String)rewarded_interstitial_ad_failed_to_load(ad_id: String, error_data: LoadAdError)rewarded_interstitial_ad_impression(ad_id: String)rewarded_interstitial_ad_clicked(ad_id: String)rewarded_interstitial_ad_showed_full_screen_content(ad_id: String)rewarded_interstitial_ad_failed_to_show_full_screen_content(ad_id: String, error_data: AdError)rewarded_interstitial_ad_dismissed_full_screen_content(ad_id: String)rewarded_interstitial_ad_user_earned_reward(ad_id: String, reward_data: RewardItem)consent_form_loadedconsent_form_dismissed(error_data: FormError)consent_form_failed_to_load(error_data: FormError)consent_info_updatedconsent_info_update_failed(error_data: FormError)
Loading and displaying ads
- initialize the plugin
- call the
initialize()method of theAdmobnode - wait for the
initialization_completedsignal
- call the
- use one or more of the following
load_*()methods to load ads from theAdmobnode:load_banner_ad(ad_request: LoadAdRequest)load_interstitia_adl(ad_request: LoadAdRequest)load_rewarded_ad(ad_request: LoadAdRequest)load_rewarded_interstitial_ad(ad_request: LoadAdRequest)
- the
Admobnode will emit the following signals once ads have been loaded or failed to load:banner_ad_loaded(ad_id: String)banner_ad_failed_to_load(ad_id: String, error_data: LoadAdError)interstitial_ad_loaded(ad_id: String)interstitial_ad_failed_to_load(ad_id: String, error_data: LoadAdError)rewarded_ad_loaded(ad_id: String)rewarded_ad_failed_to_load(ad_id: String, error_data: LoadAdError)rewarded_interstitial_ad_loaded(ad_id: String)rewarded_interstitial_ad_failed_to_load(ad_id: String, error_data: LoadAdError)
- once ads have been loaded, call corresponding
show_*()method from theAdmobnode with thead_idreceived:show_banner_ad(ad_id: String)show_interstitial_ad(ad_id: String)show_rewarded_ad(ad_id: String)show_rewarded_interstitial_ad(ad_id: String)
Banner Size
- The following methods return the size of a Banner ad:
get_banner_dimension()get_banner_dimension_in_pixels()
- These methods are not supported for
FLUIDsized ads. For banner ads of sizeFLUID, theget_banner_dimension()method will return(-3, -4)and theget_banner_dimension_in_pixels()method will return(-1, -1).
User Consent
- Methods:
get_consent_status()- Returns a consent status value defined inConsentInformation.gdupdate_consent_info(params: ConsentRequestParameters)- To be called ifget_consent_status()returns status UNKNOWN (0).reset_consent_info()- To be used only when testing and debugging your application.is_consent_form_available()load_consent_form()- To be called ifget_consent_status()returns status REQUIRED (2) andis_consent_form_available()returnsfalse.show_consent_form()- To be called afterconsent_form_loadedsignal has been emitted oris_consent_form_available()returnstrue.
Android Export
Android export requires several configuration settings.
File-based Export Configuration
In order to enable file-based export configuration, an export.cfg file should be placed in the addons/AdmobPlugin directory with the following content:
[General]
is_real = false
[Debug]
app_id = "ca-app-pub-3940256099942544~3347511713"
[Release]
app_id = "ca-app-pub-3940256099942544~3347511713"
The is_real and app_id configuration items are mandatory and if not found in the export.cfg file, then the plugin will fall back to node-based configuration.
Node-based Export Configuration
If export.cfg file is not found or file-based configuration fails, then the plugin will attempt to load node-based configuration.
During Android export, the plugin searches for an Admob node in the scene that is open in the Godot Editor. If not found, then the plugin searches for an Admob node in the project's main scene. Therefore;
- Make sure that the scene that contains the
Admobnode is selected in the Godot Editor when building and exporting for Android, or - Make sure that your Godot project's main scene contains an
Admobnode
Troubleshooting
Missing APP ID
If your game crashes due to missing APP ID, then make sure that you enter your Admob APP ID in the Admob node and pay attention to the Android Export section.
ADB logcat
adb logcat is one of the best tools for troubleshooting unexpected behavior
- use
$> adb logcat | grep 'godot'on Linuxadb logcat *:Wto see warnings and errorsadb logcat *:Eto see only errorsadb logcat | grep 'godot|somethingElse'to filter using more than one string at the same time
- use
#> adb.exe logcat | select-string "godot"on powershell (Windows)
Also check out:
https://docs.godotengine.org/en/stable/tutorials/platform/android/android_plugin.html#troubleshooting
Credits
Based on Shin-NiL's Godot Admob Plugin
Developed by Cengiz
Original repository: Godot Android Admob Plugin
Tutorials
The following is a video tutorial by 16BitDev that covers the whole process of setting up Admob for your Godot app on Android.
Contribution
This section provides information on how to build the plugin for contributors.
Prerequisites
Refreshing addon submodule
- Remove
admob/addon_templatedirectory - Run
git submodule update --remote --merge
All Plugins
Download
Support
If you need help or have questions about this plugin, please contact the author.
Contact Author