react-native-iap: RNIap is not working on Android but works in iOS with same code

Version of react-native-iap 4.4.7

Version of react-native 0.60.6

Platforms you faced the error (IOS or Android or both?) Android

Expected behavior

     async componentDidMount() {
        try {
            const result = await RNIap.initConnection();
            await RNIap.consumeAllItemsAndroid();
            console.log('result', result);
            const products: Product[] = await RNIap.getProducts(itemSkus);
            this.setState({ products }, () => {console.log(this.state.products)});
        } catch (err) {
            console.warn(err.code, err.message);
        }

Expected behavior is a list of products pulled from play console by .getProducts() printed in terminal

Actual behavior Promise is not returned. Error ‘billing is not available’

Tested environment (Emulator? Real Device?) Real Device (App is currently in production)

Steps to reproduce the behavior const itemSkus = Platform.select({ ios: [ 'com.example.1' ], android: [ 'com.example.1' ] });

     async componentDidMount() {
        try {
            const result = await RNIap.initConnection();
            await RNIap.consumeAllItemsAndroid();
            console.log('result', result);
            const products: Product[] = await RNIap.getProducts(itemSkus);
            this.setState({ products }, () => {console.log(this.state.products)});
        } catch (err) {
            console.warn(err.code, err.message);
        }
    this.purchaseUpdateSubscription = purchaseUpdatedListener(async (purchase: InAppPurchase | SubscriptionPurchase | ProductPurchase) => {
        console.log('purchaseUpdatedListener', purchase);
        const receipt = purchase.transactionReceipt;
        if (receipt) {
            try {
                // if (Platform.OS === 'ios') {
                //   finishTransactionIOS(purchase.transactionId);
                // } else if (Platform.OS === 'android') {
                //   // If consumable (can be purchased again)
                //   consumePurchaseAndroid(purchase.purchaseToken);
                //   // If not consumable
                //   acknowledgePurchaseAndroid(purchase.purchaseToken);
                // }
                const ackResult = await finishTransaction(purchase);
            } catch (ackErr) {
                console.warn('ackErr', ackErr);
            }

            this.setState({ receipt }, () => this.goNext());
        }
    },
    );

    this.purchaseErrorSubscription = purchaseErrorListener(
        (error: PurchaseError) => {
            console.log('purchaseErrorListener', error);
        },
    );
}
componentWillUnmount() {
    if (this.purchaseUpdateSubscription) {
        this.purchaseUpdateSubscription.remove();
        this.purchaseUpdateSubscription = null;
    }
    if (this.purchaseErrorSubscription) {
        this.purchaseErrorSubscription.remove();
        this.purchaseErrorSubscription = null;
    }
}

I can’t seem to figure out why this is. I’m using this exact code for iOS and it works perfectly. I have set up all products in the play console, added billings permission to the manifest file, and linked IAP package (I’m using AndroidX so the package is auto-linked). I am logged into the play store and I have the latest version of the play store, but initConnection() is still not working. I don’t know what else to do. Any help is greatly appreciated! Thank you for reading.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 38 (4 by maintainers)

Most upvoted comments

Would this help?

Unfortunately it didn’t help 😦. Would this have something to do with AndroidX migration? For some reason initConnection() is not working and I don’t know the reason why.

beta is not a must. also closed alpha is ok

Did you add <uses-permission android:name="com.android.vending.BILLING" /> to your AndroidManifest.xml file?