Shin-NiL / Godot-Android-Admob-Plugin

Android AdMob plugin for Godot Game Engine 3.2 or higher
MIT License
543 stars 66 forks source link
admob android godot godot-engine plugin

GodotAdMob

This is an Android AdMob plugin for Godot Engine (https://github.com/okamstudio/godot) 3.2.2 or higher. For Godot < 3.2 or iOS support you can use the old module.

Currently, this plugin supports:

Setup

Video Guide

Our friend dQuigz created a nice video tutorial on how to use this plugin.

Text Instructions

Here

- To avoid the mergeDex error, enable the multidex support. Edit the file ```res://android/build/build.gradle``` and insert the line `multiDexEnabled = true` inside the `android` => `defaultConfig`:

android { defaultConfig { ... multiDexEnabled = true ... } }


**NOTE**: everytime you install a new version of the Android Build Template this step must be done again, as the ```AndroidManifest.xml``` file will be overriden.

Now you'll be able to add an AdMob Node to your scene (**only one node should be added per scene**)

![Searching AdMob node](images/search_node.png)

Edit its properties

![AdMob properties](images/properties.png)

And connect its signals

![AdMob signals](images/signals.png)

## Sample Code

In the demo directory you'll find a working sample project where you can see how the things works on the scripting side.

__REMEMBER__: You still need to configure the project as described in the "Setup" section to be able to run the demo project.

## Showcase

Does this plugin really work? Yes sir! You can see a list of published games [here](showcase.md).

## Donations

Was this project useful for you? Wanna make a donation? These are the options:

### Paypal

My [Paypal donation link](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=3MJE3M4FMJYGN&lc=BR&item_name=Shin%2dNiL%27s%20Github&item_number=Github&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted)

### Brave Browser
If you're a Brave browser user, please consider donating some BATs ;)

## API Reference

### Properties
```python
# If true use your real ad, if false use test ads. Make sure to only set it to true with your published apk, otherwise you can be banned by Google
# type bool, default false
is_real

# If true, displays banner on the top of the screen, if false displays on the bottom
# type bool, default true
banner_on_top

# The banner size constants
# Valid values are: "ADAPTIVE_BANNER", "SMART_BANNER", "BANNER", "LARGE_BANNER", "MEDIUM_RECTANGLE", "FULL_BANNER", "LEADERBOARD"
banner_size

# Your app banner ad ID
# type String, optional
banner_id

# Your app interstitial ad ID
# type String, optional
interstitial_id

# Your app rewarded video ad ID
# type String, optional
rewarded_id

# Your app rewarded interstitial ad ID
# type String, optional
rewarded_interstitial_id

# If true, set the ads to children directed. If true, max_ad_content_rate will be ignored (your max_ad_content_rate would can not be other than "G")
# type bool, default false
child_directed

# If ads should be personalized. In the European Economic Area, GDPR requires ad personalization to be opt-in.
# type bool, default true
is_personalized

# Its value must be "G", "PG", "T" or "MA". If the rating of your app in Play Console and your config of max_ad_content_rate in AdMob are not matched, your app can be banned by Google
# type String, default G
max_ad_content_rate

# If true, ads should be displayed after consent verification (calling method request_consent_info_update())
ads_using_consent

# True for testing purpose only
# False for production environment
testing_consent

Methods


# Load the banner (and show inmediatly)
load_banner()

# Load the interstitial ad
load_interstitial()

# Load the rewarded video ad
load_rewarded_video()

# Load the rewarded interstitial ad
load_rewarded_interstitial()

# Show the banner ad
show_banner()

# Hide the banner ad
hide_banner()

# Move banner after loaded
move_banner(on_top: bool)

# Show the interstitial ad
show_interstitial()

# Show the rewarded video ad
show_rewarded_video()

# Show the rewarded interstitial ad
show_rewarded_interstitial()

# Check if the interstitial ad is loaded
# @return bool true if is loaded
is_interstitial_loaded()

# Check if the rewarded video ad is loaded
# @return bool true if is loaded
is_rewarded_video_loaded()

# Check if the rewarded interstitial ad is loaded
# @return bool true if is loaded
is_rewarded_interstitial_loaded()

# Resize the banner (useful when the orientation changes for example)
banner_resize()

# Get the current banner dimension
# @return Vector2 (width, height)
get_banner_dimension()

# Verify consent status
request_consent_info_update()

# Reset consent status
# Should by called only for testing purpose OR 'if you decide to remove the UMP SDK completely from your project.'
# See: https://developers.google.com/admob/android/privacy#reset_consent_state
reset_consent()

Signals

# Banner ad was loaded with success
banner_loaded

# Banner ad has failed to load
# @param int error_code the error code
banner_failed_to_load(error_code)

# Interstitial ad was loaded with success
interstitial_loaded

# Interstitial ad was opened
interstitial_opened

# Interstitial ad was closed
interstitial_closed

# Interstitial ad has failed to load
# @param int error_code the error code
interstitial_failed_to_load(error_code)

# Interstitial ad has been clicked
interstitial_clicked

# The user has provided an interstitial impression.
interstitial_impression

# Rewarded video ad was loaded with success
rewarded_video_loaded

# Rewarded video ad was opened
rewarded_video_opened

# Rewarded video ad was closed
rewarded_video_closed

# Rewarded video ad has failed to load
# @param int error_code the error code
rewarded_video_failed_to_load(error_code)

# Rewarded interstitial ad was loaded with success
rewarded_interstitial_loaded

# Rewarded interstitial ad was opened
rewarded_interstitial_opened

# Rewarded interstitial ad was closed
rewarded_interstitial_closed

# Rewarded interstitial ad has failed to load
# @param int error_code the error code
rewarded_interstitial_failed_to_load(error_code)

# Rewarded interstitial ad has failed to show
# @param int error_code the error code
rewarded_interstitial_failed_to_show(error_code)

# Rewarded video/interstitial ad was watched and will reward the user
# @param String currency The reward item description, ex: coin
# @param int amount The reward item amount
rewarded(currency, amount)

# Rewarded video was clicked
rewarded_clicked

# The user has given an impression for a rewarded video.
rewarded_impression

# Good for nothing. Only used for debug information. 
consent_info_update_success

# Error on consent verification
consent_info_update_failure(error_code, error_message)

# Now you can show ads to user
consent_app_can_request_ad(consent_status)

Compiling the Plugin (optional)

If you want to compile the plugin by yourself, it's very easy:

  1. Clone this repository;
  2. Checkout the desired version;
  3. Download the AAR library for Android plugin from the official Godot website;
  4. Copy the downloaded AAR file into the admob-plugin/godot-lib.release/ directory and rename it to godot-lib.release.aar;
  5. Configure the demo project according to the "Setup" instructions. Install the "Android Custom Template" for the demo project. This generates the required build configuration.
  6. Using command line go to the admob-plugin/ directory;
  7. Run gradlew build.

If everything goes fine, you'll find the .aar files at admob-plugin/godotadmob/build/outputs/aar/.

Troubleshooting

References

Based on the works of:

License

MIT license