5/07/2018

Debugging an Android App that uses In-App Purchasing

In order to get In-App Purchasing to work in the first place, make sure you meet the following requirements:
  • Manifest file must include com.android.vending.BILLING permission.
  • APK is
    • built in release mode
    • signed with the release certificate
    • uploaded to alpha/beta distribution channel in the Developer Console
    • published to testers
  • in-app products are published in the Developer Console and their status is set to active.
  • Test account is added in Developer Console. You cannot test the purchasing process with your developer account!
  • Test account is opted-in as a tester and it's linked to a valid payment method.
Now, to debug the application with in-app purchasing working, you need to change few things:

In the Manifest add the following as an attribute to the application node:
android:debuggable="true"
tools:ignore="HardcodedDebugMode"
In your Build.gradle file (for the app module) under android > buildTypes > release, add:
debuggable true
Compile your app. Because of the previous changes, it will be debuggable now, even if you build it in release mode. Ensure that this APK:
  • is built n release mode
  • has the same versionCode as the one uploaded to Developer Console.
  • is signed with the same certificate as the one uploaded to Developer Console.

Now you can debug the app from from Android Studio as if you had built a debug version, and in-app purchasing will work. Change the code, recompile, everything works fine as long as you stick to release mode.

To test in an Adroid Virtual Machine or emulator, you need to pick an image that includes Play Store. As of this writing, the only images that do so are Nexus 5 and Nexus 5X. You may find a way to install Play Store on other images, e. g. from GApps, but I avoided that hassle.

Important: before you build a version to officially release to PlayStore, remember to revert the above changes! You don't want to make it too easy for hackers/pirates ...

Sources:
https://stackoverflow.com/questions/11068686/this-version-of-the-application-is-not-configured-for-billing-through-google-pla
https://stackoverflow.com/questions/36113347/is-it-possible-to-debug-locally-google-plays-in-app-billing-in-android-studio
https://developer.android.com/google/play/billing/billing_testing

No comments:

adaxas Web Directory