Is it possible to debug locally Google Play's in-app billing in Android Studio?
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
- 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.
- Have these settings:
In
AndroidManifest.xml
underapplication
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
Generate a signed APK from Android Studio
Attach your device for USB debugging. Remove current install:
adb uninstall {yourdomain}.{yourpackagename}
- Install it (from the release path)
adb install app-release.apk
- 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
The following worked for me launching from my IDE (Android Studio)
1) Go to your https://play.google.com/apps/publish/ Under 'Developer' Account/Settings/Account details/License Testing
2) Add the 'Default Google Play' email address that corresponds with the device you are testing
Source: https://engineering.memrise.com/faster-in-app-billing-subscriptions-testing-8e68551b4e2f
Perhaps another approach:
Similar in most ways to what is mentioned here except you just point to your release keystore within your debug buildType.
Exact steps:
1) In your app Gradle file in the android
tag add a release signing config:
signingConfigs {
release {
storeFile file("Path_to_your_Production_release_Keystore.jks")
storePassword 'your_keystore_password'
keyAlias 'your_key_alias'
keyPassword 'your_key_password'
}
}
and add the signing config to your debug buildType:
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-project.txt', 'proguard-google-api-client.txt'
}
debug {
signingConfig signingConfigs.release
debuggable true
}
}
2) Make sure the versionCode
and versionName
in your app gradle > defaultConfig
section matches exactly what's in the apk you uploaded to the play store:
defaultConfig {
applicationId "com.groovypackagename.groovyapp"
minSdkVersion 16
targetSdkVersion 24
versionCode 56
versionName "0.9.6"
multiDexEnabled true
resConfigs "en"
}
3) Make sure to add the billing permission to your manifest:
<uses-permission android:name="com.android.vending.BILLING" />
4) Don't forget to add your IAB (In App Billing) products per the docs
5) Set your break points and debug per usual.
6) After you have successfully tricked out your code, don't forget to clean up at least the changes in your gradle file such as removing the signing config so your kestore passwords aren't floating around in space.
With any luck you will be able to do local debugging for your IAB code.
Cheers.