Is it possible to debug locally Google Play's in-app billing in Android Studio?

jenson-button-event picture jenson-button-event · Mar 20, 2016 · Viewed 17k times · Source

I am getting this error testing in-app subscription products locally.

authentication is required. you need to sign in to your google account

I was able to check the the inventory for the product but shouldn't I also be able to purchase it?

There are a number of posts about why this error might occur which I thought were addressed:

  • the product is released in the beta channel with in-app billing enabled
  • i am logged into Play Store with a test user licensed account on the device.

Is the only way to test actual purchases via the beta/alpha channels - not straight from android studio. This post suggests it possible (see screen shot)

http://developer.android.com/google/play/billing/billing_testing.html#billing-testing-test

Answer

jenson-button-event picture jenson-button-event · Mar 21, 2016

In essence, in-app billing payments can only be tested with a release-signed apk (the one we upload to Google Play Console).

Here are some steps that got me attached to a signed apk with Android Studio:

I'm on Windows. It helps having adb.exe in the PATH, for me that's:

C:\Users{your-username}\AppData\Local\Android\sdk\platform-tools

  1. In Google Play Console, ensure the app is published (< is a one-time manual step after its initially processed) in alpha or beta channel and you have a licensed test gmail account (from the Account Settings section) that is also in the list of alpha/beta testers and is not the owner of the app account. This account is the only account on the device. Release the apk and ensure it all works from an installed version from the Play Store.
  2. Have these settings: In AndroidManifest.xml under application node
android:debuggable="true"
tools:ignore="HardcodedDebugMode"

Note: Propably, you need to add: xmlns:tools="http://schemas.android.com/tools" property to your manifest tag. It may look like:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="your.package"
 xmlns:tools="http://schemas.android.com/tools">

And in your build.gradle file under android > buildTypes > release, add:

debuggable true

  1. Generate a signed APK from Android Studio

  2. Attach your device for USB debugging. Remove current install:

adb uninstall {yourdomain}.{yourpackagename}

  1. Install it (from the release path)

adb install app-release.apk

  1. Open the app on the device. From Android Studio's Run menu, last option is "Attach debugger to Android Process" - select your device. You are now debugging.

NB for in-app billing the build number needs to match the one currently published on Play Store