• 6

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

React Native Android In App Purchase Error

Version of react-native-iap


Version of react-native


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


Expected behavior

Listing Items or Buying an Item

Actual behavior

Products Array is empty

Tested environment (Emulator? Real Device?)

Real Device

Steps to reproduce the behavior

I got two errors: E_UNKNOWN An unknown or unexpected error has occured. Please try again later. adding purchase listener is only provided in ios. This is my Item's id: ozann_ozan

Some codes:

                onPress={() => this.buyItem('ozann_ozan')}

const itemSkus = Platform.select({
    ios: [
    android: [

      componentWillMount() {

async componentDidMount() {
      try {
        const products = await RNIap.getProducts(itemSkus);
        this.setState({ products });
      } catch(err) {
        console.warn(err); // standardized err.code and err.message available
    getItems = async() => {
      const products = await RNIap.getProducts(itemSkus);
      try {
        const products = await RNIap.getProducts(itemSkus);
        // const products = await RNIap.getSubscriptions(itemSkus);
        console.log('Products', products);
        this.setState({ productList: products });
      } catch (err) {
        console.warn(err.code, err.message);
    getAvailablePurchases = async() => {
      try {
        console.info('Get available purchases (non-consumable or unconsumed consumable)');
        const purchases = await RNIap.getAvailablePurchases();
        console.info('Available purchases :: ', purchases);
        if (purchases && purchases.length > 0) {
            availableItemsMessage: `Got ${purchases.length} items.`,
            receipt: purchases[0].transactionReceipt,
      } catch (err) {
        console.warn(err.code, err.message);
    buyItem = async(sku) => {
      console.info('buyItem: ' + sku);
      try {
        const purchase: any = await RNIap.buyProduct(sku);
        this.setState({ receipt: purchase.transactionReceipt }, () => this.goToNext());
      } catch (err) {
        console.warn(err.code, err.message);
        const subscription = RNIap.addAdditionalSuccessPurchaseListenerIOS(async(purchase) => {
          this.setState({ receipt: purchase.transactionReceipt }, () => this.goToNext());

I had the same issue, and even though this is a bit old, I figured it would be useful to provide some support for those who have problems. As I just came across this problem myself and it was annoying as the documentation doesn't really mention this clearly.

On android Only - you need to open a connection to the billing service. This used to be RNIAP.prepare(), but it is now RNIAP.initConnection(). This does nothing on iOS but it is a required step for the RNIAP.getProducts(itemSkus) to work.

Also, if you are trying to receive subscriptions, for some reason it is agnostic on iOS and you get them if you call RNIAP.getProducts(itemSkus) but on android you need to specify them as subscriptions for it to work. You can do this with RNIAP.getSubscriptions(itemSkus).

I was fighting with this for a couple of hours on Android and iOS for different issues, so I hope this helps.


  • 1
Reply Report
      • 1
    • yes really thank you because you share your knowledge. I figured out this issue recently. Before I solved that, I used different library for android devices. Thank you again, it is really painfully and people can solve the issue because of your helpful answer.
    • What should the RNIAP.initConnection() return ? I'm getting an empty array when I'm calling this method.