diff --git a/RNIapExample/android/app/build.gradle b/RNIapExample/android/app/build.gradle index 56f2c21ef..3fc400a6d 100644 --- a/RNIapExample/android/app/build.gradle +++ b/RNIapExample/android/app/build.gradle @@ -94,7 +94,7 @@ def enableSeparateBuildPerCPUArchitecture = false def enableProguardInReleaseBuilds = false android { - compileSdkVersion 23 + compileSdkVersion 27 buildToolsVersion '27.0.3' defaultConfig { @@ -137,11 +137,11 @@ android { } dependencies { - compile project(':react-native-gesture-handler') - compile project(':react-native-iap') - compile fileTree(dir: "libs", include: ["*.jar"]) - compile "com.android.support:appcompat-v7:23.0.1" - compile "com.facebook.react:react-native:+" // From node_modules + implementation project(':react-native-gesture-handler') + implementation project(':react-native-iap') + implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation "com.android.support:appcompat-v7:27.0.3" + implementation "com.facebook.react:react-native:+" // From node_modules } diff --git a/android/src/main/java/com/dooboolab/RNIap/RNIapModule.java b/android/src/main/java/com/dooboolab/RNIap/RNIapModule.java index e22c4477f..7caa565b5 100644 --- a/android/src/main/java/com/dooboolab/RNIap/RNIapModule.java +++ b/android/src/main/java/com/dooboolab/RNIap/RNIapModule.java @@ -66,7 +66,9 @@ public class RNIapModule extends ReactContextBaseJavaModule { private IInAppBillingService mService; private BillingClient mBillingClient; - ServiceConnection mServiceConn = new ServiceConnection() { + private boolean clientReady = false; + + private ServiceConnection mServiceConn = new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName name) { mService = null; } @@ -76,7 +78,7 @@ public void onServiceConnected(ComponentName name, IBinder service) { } }; - LifecycleEventListener lifecycleEventListener = new LifecycleEventListener() { + private LifecycleEventListener lifecycleEventListener = new LifecycleEventListener() { @Override public void onHostResume() { @@ -100,7 +102,7 @@ public void onHostDestroy() { } }; - public RNIapModule(ReactApplicationContext reactContext) { + private RNIapModule(ReactApplicationContext reactContext) { super(reactContext); this.reactContext = reactContext; reactContext.addLifecycleEventListener(lifecycleEventListener); @@ -116,12 +118,13 @@ private void ensureConnection (final Promise promise, final Runnable callback) { // This is the key line that fixed everything for me intent.setPackage("com.android.vending"); - BillingClientStateListener billingClientStateListener = new BillingClientStateListener() { + final BillingClientStateListener billingClientStateListener = new BillingClientStateListener() { @Override public void onBillingSetupFinished(@BillingClient.BillingResponse int responseCode) { - if (responseCode == BillingClient.BillingResponse.OK) { + if (responseCode == BillingClient.BillingResponse.OK && !clientReady) { Log.d(TAG, "billing client ready"); callback.run(); + clientReady = true; } else { rejectPromiseWithBillingError(promise, responseCode); } @@ -130,6 +133,7 @@ public void onBillingSetupFinished(@BillingClient.BillingResponse int responseCo @Override public void onBillingServiceDisconnected() { Log.d(TAG, "billing client disconnected"); + clientReady = false; } }; diff --git a/package.json b/package.json index 9494b63b5..b0df17e7f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-iap", - "version": "2.4.0-betal", + "version": "2.4.0-beta2", "description": "React Native In App Purchase Module.", "main": "index.js", "types": "index.d.ts",