How To Test Google Play Billing on Simulator
Testing the integration of Google Play Billing system in your Android application is important. As an iOS developper, I know that this feature can be tricky to test. What I really like on Android development is that we can test the Google Play Billing system on emulator. Before setting it up, there are some pitfalls to avoid. You can find several documentation about the prerequisites, but not much about how to configure your simulator (Virtual Device).
Prerequisite
- Add the billing permission in the Android.manifest (in your source code)
<uses-permission android:name="com.android.vending.BILLING" />
- Upload a release on your Google Play Console. (in Play Console)
- Create an In App Product in the Google Play Console. (in Play Console)
- Add you Google Account as a tester of your application (in Play Console).
Publish the application on a test track
You must publish you application on a test track if you want that your SKU request works. Note that after I published my app to the test track, it takes 5 or 7 days to be reviewed.
So be patient, before being able to test your IAP… A better way is to take this condition in your workflow.
If you miss this step, you will not be able to debug your SKU. The request will return an empty list ok SKU.
billingClient.querySkuDetailsAsync(params.build()) { billingResult, skuDetailsList -> ...
Also, double check that you added SKU in the parameters, and that their ids match those on Google Play Console.
Create the right emulator from AVD (Android Virtual Device).
The virtual device on which you want to test the Google Play Billing must support the Play Store feature. When you create your virtual device, take care to select a compatible device definition.
For my first tests, I did all the prerequisites, but still cannot connect with my BillingClient object. In this case the error code is 3 and you get the following error message : Billing service unavailable on device. 🕵🏻♂️🕵🏻♀️
Setup the Google Play application on your emulator.
Now, I have created a Virtual Device compatible with Google Play. I thought that I will retrieve my In App product with my Virtual Device. NO!
The API is returning a weird error. In this case the error code is 3 and you get the following error message : Google Play In-app Billing API version is less than 3. 🕵🏻♂️🕵🏻♀️
The solution, is to link you Play Store application with one of your Google Account.
Add payment method to your Google Play Application without being charged.
Ok, in this part I don’t really get how it’s really work. Sometimes I have to configure Google Play with an account that includes a payment method, and sometimes no. The important thing is that we don’t want to be charged. For this be sure to have the payment popin with test options.
Check your test email purchase
Be sure that you acknowledge the purchase in your code. And in this case you will receive an confirmation e-mail from Google. Check that you are still in a test environment.
If you enjoyed this post, please leave some claps. 👏👏👏
You can clap up to 50 times, so get clicking/tapping! 😉