Google Play
This guide explains how to create and configure in-app purchases for Google Play.
Register developer account
Sign up for a Google Play developer account. There is a $25 one-time registration fee to become a publisher on Google Play.
Having issues in the registration process? Please see this answer on Google’s support pages.
Create your app
In this section we will create a new app in Google Play, connect it within Unity and add some in-app purchases.
Create app in Google Play
In case you’ve opened the Developer Console for the first time, you will see an overview of actions. Start with publishing a new app.
Follow the task lists shown on the Dashboard and fill out all required sections, for example the ones in the Store presence category.
Configuring app in Unity
If you would like to view the sample shop scenes included in UniPay, add them to the build. Switch to the Android platform (File > Build Settings
) and open the Unity settings for Android by pressing Player Settings.
In the Other Settings section, change the bundle identifier to what you like it to be, but keep the format of com.company.appname. If you already have a published app on Google Play, make sure that the bundle identifier here is the same as displayed for your app in the Developer Console.
The bundle version and bundle version code in the Unity settings for Android will default to 1.0 / 1 for new apps, which is fine for now. If you are testing with a new app, you do not have to change this each time for every build! Just keep the 1.0 / 1 until your app is done and about to go live globally. If you’ve published an app on Google Play already, replace this with your current associated bundle version and version code from the Developer Console.
If you didn't publish an app before, you probably did not create a Keystore yet. To do so, scroll down in the settings for Android and expand the Publishing Settings. Click on Keystore Manager in order to create a new key. Save this Keystore somewhere safe! If you lose your Keystore, you cannot submit app updates in Google Play anymore. If you would like to use an existing Keystore, choose Custom Keystore instead.
On the Google Play dashboard, the bundle identifier will be displayed on the application overview once you've uploaded an APK. When exporting the build, note that Development Build needs to be unchecked, even if we are going to upload it to a testing track later. We are only going to save the build created in this process on the hard drive (and not using Build And Run), because Google Play still needs some settings to be configured first.
Add test accounts
Open the Test and release > Testing
page and upload your exported build to the Closed (Alpha), Open (Beta) or Internal Testing track. For this guide we choose the Internal testing track.
After creating and uploading a release to test, specify your tester's emails for this app. The list of tester emails can be shared for different apps. If you would like to define a global list, you can do so by navigating back to All Apps > Settings > License testing and creating a new email list. Otherwise, you can also create a new email list here on the testing page or edit an existing email list.
License testers will not be charged for test purchases. To test in-app purchases, you will have to add an email address which is NOT the email used to register your Google Play Developer account and then use this email on your device. Otherwise, you will get the error message "The publisher cannot purchase this item". For more information about testing, please refer to the official Google billing documentation.
Create in-app purchases
In Google Play's Monetise with Play > Products > In-app products / Subscriptions
section, add your product and define a product identifier (ID). Consumable and non-consumable products go into the In-app products tab, whereas subscription products are in a separate tab. Only active products can be purchased. Note: If you add translations for your products, UniPay is able to display product details in the user's native language, which naturally increases IAP conversion rates (recommended). For a description of Non-Consumable, Consumable and Subscription product types please refer to Google's documentation.
Note: The Multi-quantity field should be left disabled, since Unity IAP does not make use of it.
Open UniPay's Project Settings in Unity and define the exact same IAPs using the same product identifiers.
Testing IAPs
Don't worry: because you've uploaded an internal, alpha or beta build, the app will not be visible publicly – only for you to test it. The release process can take several days before your app is available for testing.
After you've waited a few days for your app to be processed by Google (up to 48 hours), you should be able to test your release. If you chose a testing track previously, the Test and release > Testing > Your Test Track > Testers
page displays a link to subscribe for testing. Open it with the corresponding Gmail account you invited (that is not the Google Play admin account) and join the testing program.
Go back to Unity and open the Build Settings. First, enable Development Build. This enables log messages sent by UniPay on your device for debug purposes. Don’t forget to disable Development Build for your live apps. Finally press Build And Run to deploy your project to your connected Android device. If you change values in the IAP Settings window of UniPay later, you need to uninstall your app from the device before deploying it again (so that any locally cached product data is wiped).
When the app has started on your device, enter your shop scene and try to purchase a product. Log in with your test account when prompted. If it does not prompt for your Google Play account, go to your Google Play device settings verify that you are authenticated with that test account. Purchasing a product in your app should show a popup similar to this one:
Unsolved Errors
If you can't see any products or if the purchase popup does not show up at all, you may have some issues with your Unity / Google Play settings and / or errors on the device.
Please verify that all of the following points have been met:
- app bundle identifier in Unity matches the app identifier in Google Play
- app is released on an internal, alpha or beta track in Google Play (draft apps do NOT work!)
- in-app product identifiers in the UniPay In-App Purchasing Project Settings matches the IAP identifiers created in Google Play
- in-app product are active in Google Play
- you have added test user accounts in Google Play and joined the testing program
- you are logged in with a Google Play the associated test user account on the device
Still having issues?
You can install Unity's Android Logcat Package for reading the device log over your USB connection. Filter for Unity messages to remove any irrelevant events. If you want to debug on your PC manually, open a command prompt and navigate to the adb.exe on your hard drive (located where you installed the Android SDK > platform-tools directory). Next, enter adb.exe logcat –s Unity to start the debugging connection. Run your app on the device again and watch out for errors!
Please note that in case of issues with this process, I am not able to guess or remotely debug the exact cause for you. Since a major part of this guide is not written for UniPay in particular, there is a high chance that your issue has been experienced by many, many other developers before and is covered somewhere already - debug your device, do a Google search for the error message and look out for popular Android developer or Unity IAP threads!
If you need help with the app setup, testing process or solving issues with your app's connection to Google Play, I am providing extended support for this via PREMIUM support. Contact me on the Unity Forum or on Discord to discuss your requirements.