How to test In-app Billing on an emulator?
Asked Answered
H

1

12

Is it possible to disable in-app billing/purchase and test my application on an Android Emulator? I want to do some functional testing of my application on multiple emulators. Later on I would test the 'in-app billing' on a real device.

Anyone have experience? How should I do this?

From Google: http://developer.android.com/guide/market/billing/billing_testing.html

To test in-app billing in an application you must install the application on an Android-powered device. You cannot use the Android emulator to test in-app billing. The device you use for testing must run a standard version of the Android 1.6 or later platform (API level 4 or higher), and have the most current version of the Android Market application installed.

Update 2022

Recently re-checked:

  • Even if we Emulate a system-image which targets Google-Play (instead of Google APIs),
  • update Google-play services to latest,
  • and follow the "Goole Wallet" app's and/or "Google Pay" app's add-credit-card form till end successfully.

Said App instead of adding credit-card as payment-method, just shows message:

screen-shot

Note that the message is confusing, as we were trying to add credit-card, and did not try to use "Tap to Pay".

Halloween answered 29/9, 2014 at 12:33 Comment(5)
Did you try to just run the app on an emulator? As long as you aren't trying to use the in-app billing functionality there shouldn't be any issue. Your app should also be able to detect if in-app billing is available and still function (in a limited fashion) if not.Bernabernadene
I tried it, but the app doesn't work on an emulator, since it depends on google services.Halloween
Use an AVD with Google APIs (see documentation).Bernabernadene
The problem is that the app does not start up in de AVD, since this AVD is not a real device and the app needs to communicate with real google services, attached to a real google account. In-App billing checks what services that the user already own/has bought.Halloween
As described in the documentation I linked above you have to check for availability of Google Play Services. Anyway, it also says that an AVD with Google APIs running Android 4.2.2+ can be used to test them. I'm not sure about the requirement of a Google account. You should try to disable all in-app billing functionality when running in an emulator, e.g., using dynamic checks.Bernabernadene
C
7
  1. Install an emulator that has already google playstore installed, on a system image that supports google service api

My emulator spec:

Pixel 3a API 31
ABI: x86_64
System image: Android API 31 (Google Play)
  1. Create a closed testing track in google playstore console

  2. Add your gmail to license testing and closed testing email list

  3. Wait for your closed testing to be approved and available for testers.

  4. If you're using an existing emulator, please wipe data and cold boot

  5. Login as a tester account in gmail app as the first thing when you launch the emulator

  6. Browse closed testing invitation url, and accept invitation to take part in closed testing track

  7. IMPORTANT Make sure you're using the same application id (e.g. com.your.company.app), version code (e.g. 1.3.0) and version name(a.k.a build number) as the closed testing binary.

  8. That's all. Test payments in the emulator.

For step 2 ~ 4 you can refer to this wonderful doc from revenue cat: https://docs.revenuecat.com/docs/google-play-store

Cupo answered 1/11, 2021 at 13:0 Comment(3)
You are a life saver! I forgot that I have ".dev" package prefix in build script for development builds.Holsinger
But this way we can't debug it, right?Compression
This was the only answer working for me for testing android subscriptions inside the emulator. Just be sure to have installed the "Google Play" system in your emulatorNovotny

© 2022 - 2025 — McMap. All rights reserved.