Adds Google Play Billing dependencies to your game and provides functionality for InApp Purchases on Google Play Console.
First you will want to clone this Repo. you will have to build the Plugin yourself since you will have to manually add your Google Play Application ID for the Android Plugin to connect with your game.
Simply download the repo, or get git installed and run in your terminal:
git clone https://github.com/skyelynwaddell/godot-google-play-plugin.git
Make sure you have the latest version of Android Studio, and your Godot project already setup to export for Android. This tutorial won't cover that. Once your project loads on Android first and you have registered with Google Play Console, then you can implement this Plugin. Please read the official docs for more info.
Application ID is found on Google Play Console.
Goto your Game Project > Grow Users > Play Game Services > Setup and Management > Configuration
You should see your application name with the Project ID underneith it.
This is your Application ID!
This method does not work if you want Push Notifications with Firebase you will need to manually compile the plugin to enter your firebase project details, please instead refer to Method 2 if this is the case.
Open the GooglePlayPlugin in Terminal and run
./build.sh
It will ask you for your Google Application ID. This is found on Google Play Console, and needs to be injected into the build.
This will build the plugin as .aar files into /library/build/outputs/aar
If this fails for some reason, resort to method 2.
You will need to open the project, and locate the AndroidManifest.xml
file
app > library > manifests > AndroidManifest.xml
You will see a line that says
android:name="com.google.android.gms.games.APP_ID"
android:value=""
Replace the android:value with your actual Google App ID found on Google Play Console!
If you want to enable push notifications, before you build the plugin go on Firebase and setup your project. Once you do you will be able to setup Messaging, and you can click the little Android icon. It will take you through the easy setup and you will end up with a google-services.json file. This file is not required to be put in the Android Studio project like it says, since this is a plugin it works a bit differently. You will have to manually supply the details in the GodotAndroidPlugin.kt file.
Goto /library/src/main/java/com.skyescloud.library/GodotAndroidPlugin.kt
in this file there a 3 lines close to the top of the document
var FIREBASE_APPLICATION_ID = "" // Looks like 1:328424237492384:android:fjshf84h82f2fhc
var FIREBASE_CURRENT_KEY = "" // looks like HSA9hs9yhnd080n0asd9uhsadAUSDHNd
var FIREBASE_PROJECT_ID = "" // looks like my-superapp-24dvv
make sure you fill out these strings with your data found in the google-services.json file. Once done you are good to proceed.
Once Done Save, and if Gradle asks you to Sync at the top. Make sure you do!!
Once you have done that you can open the GooglePlayPlugin project folder in your terminal and run the following command
./gradlew :library:assemble
This will build the plugin as .aar files into /library/build/outputs/aar
First navigate (inside of godot editor)
to the root directory and make a new folder called addons
(if not already present)
now navigate in to the Android Studio Repo, and inside the root folder there will be a folder called GooglePlayPlugin
Drag this entire folder into your Godots /addons
folder
You will want to navigate and find the compiled .aar files now, so go in the android repo and navigate the following folder
/library/build/outputs/aar/
in here there will be 2 files we recently just compiled with your Application ID attached to them.
- library-release.aar
- library-debug.aar
Inside your /addons/GooglePlayPlugin
folder there is a folder called bin
, open it and it will contain the following 2 folders (if it doesnt create them):
- release
- debug
Copy each of the .aar files into their respective folder on your godot project.
- library-release.aar > /addons/GooglePlayPlugin/bin/release/
- library-debug.aar > /addons/GooglePlayPlugin/bin/debug/
First go to your Project Settings, and go into Plugins and you should now see GooglePlayPlugin, make sure it is activated.
Once you have activated the plugin you may need to restart your project for GooglePlayPluginSingleton to be loaded into your project. But you shouldnt.
First setup your project for Android. You can goto firebase console on their site and make one.
make sure you follow the above steps for "Setting up Push Notifications"
Once done you can compile the android .aar files, and then in your godot GooglePlayPluginSingleton script, un-comment the firebase_init()
function.
You should see your device token appear when you call this function and Godot receives the signal in _on_firebase_login_success()
which will return the device token.
Try calling a method from your scrip from GooglePlayPluginSingleton.
You can call any method inside GooglePlayPluginSingleton.gd to interact with the Google API on Android, and it is well documented with what each function does and the parameters they take.
Below lists all the signals that are called from android, and functions you can call from Godot to interact with the Google Play API.
_on_debug_message(msg:String) -> void
Returns general messages from android.
_on_login_success() -> void
Signal received when player succesfully logs into Play Game Services
_on_firebase_login_success(deviceToken:String) -> void
Signal received after firebase_init() is called and a player successfully authenticates with Firebase and we get their device token you can use for later communication.
_on_achievement_unlocked(achievementID:String) -> void
Signal received when Google Play succesfully unlocks achievement
_on_achievement_incremented(achievementID:String) -> void
Signal received when a players achievement progress has been succesfully updated by Google Play
_on_event_updated(eventID:String) -> void
Signal received when a users score in an event has been updated
_on_leaderboard_updated(leaderboardID:String) -> void
Signal received when a users score in a leaderboard has been updated
_on_purchase_success(sku:String) -> void
Signal received when Google Play confirms a successful purchase (returns the product ID from Google Play Console)
_on_purchase_failed(sku:String) -> void
Signal received when Google Play detected a failed purchase whether it was cancelled, or failed billing. (Returns product ID from Google Play Console)
Functions you can call in Godot from the GooglePlayPluginSingleton script to interact with Google Play
toast_maketext(msg:String) -> void
Create an Android Popup/Toast message
firebase_init() -> void
Authenticates the player with Firebase so we can retrieve their device token for later communication.
login() -> void
Logs the player into Google Play Game Services. Called at _on_ready() in the plugin by default.
achievements_unlock(achievementID:String, incremental:bool) -> bool
Unlocks an achievement by Google Play Achievement ID, and if it is incremental it will progress the step count to complete the achievement +1
achievements_show() -> bool
Opens the popup modal to show the Google Play achievements
leaderboard_show(leaderboardID:String) -> bool
Opens the popup modal to show Google Play Leaderboard by ID
leaderboard_update(leaderboardID:String, score:int) -> bool
Call to update a players score in the leaderboard
event_show_all() -> bool
Opens popup modal with all current events in the game
event_show(eventID:String) -> bool
Opens a popup modal for a specific event by Event ID on Google Play Console
event_update(eventID:String) -> bool
Progresses the players score in the event +10 points
purchase(sku:String) -> bool
Request a purchase to Google Play Billing by Product ID found on Google Play Console
validate_plugin() -> bool
Returns true or false if the plugin is currently active and running on the current platform