React-native-iap: [Android] getProducts return always an empty array

Created on 25 Apr 2018  ·  19Comments  ·  Source: dooboolab/react-native-iap

Version of react-native-iap

0.3.15

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

Android

Expected behavior

Get All products

Actual behavior

All work fine on iOS but getProducts return always an empty array on android.
I think its a config problem however i followed each step...

APK upload with billing permission / merchant account set up / Create in app purchase...

🙏 help wanted

Most helpful comment

@vadermemo @martinberbesson Hi~ Could you share your js code for itemSkus? Did you set up like below code?

export const PURCHASE_ITEMS = Platform.select({
  ios: [
    'productid_1',
    'productid_2',
  ],
  android: [
    'productid_1',
    'productid_2',
  ],
});

Also, draft app testing is no longer supported. Pleaser refer to guide. Make sure to publish your app to alpha or beta channel.

All 19 comments

Same issue here

My snippet:

  RNIap.prepare().then(responsePrepare => {
    console.log("=============>responsePrepare:" + responsePrepare);
    RNIap.getProducts(itemSkus).then(response => {
        this.setState({ items  : response});
        console.log("=============>response:" + JSON.stringify(response));
    });
  });

My response on adb.logcat (Android)

208 28473 28524 I ReactNativeJS: Running application "testingIap" with appParams: {"rootTag":11}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
04-25 17:04:04.228 1140 1150 I AccountManagerService: getTypesVisibleToCaller: isPermitted? true
04-25 17:04:04.230 1140 2059 I AccountManagerService: getTypesVisibleToCaller: isPermitted? true
04-25 17:04:04.232 24842 24933 I Finsky : [4061] com.google.android.finsky.billing.iab.ab.b(46): com.projectbundle: Account from first account - [uuAJBL1tLX2MAj69S-olEslXXXX]
04-25 17:04:04.233 28473 28473 D RNIapModule: billing client ready
04-25 17:04:04.303 28473 28524 I ReactNativeJS: =============>responsePrepare:null
04-25 17:04:04.308 28473 28524 I ReactNativeJS: =============>responsePrepare:null
04-25 17:04:04.328 1140 2107 I AccountManagerService: getTypesVisibleToCaller: isPermitted? true
04-25 17:04:04.330 1140 1896 I AccountManagerService: getTypesVisibleToCaller: isPermitted? true
04-25 17:04:04.339 1140 2095 I AccountManagerService: getTypesVisibleToCaller: isPermitted? true
04-25 17:04:04.340 1140 1679 I AccountManagerService: getTypesVisibleToCaller: isPermitted? true
04-25 17:04:04.343 24842 24854 I Finsky : [4020] com.google.android.finsky.billing.iab.ab.b(46): com.projectbundle: Account from first account - [uuAJBL1tLX2MAj69S-olEslXXXX]
04-25 17:04:04.347 24842 24853 I Finsky : [4019] com.google.android.finsky.billing.iab.ab.b(46): com.projectbundle: Account from first account - [uuAJBL1tLX2MAj69S-olEslXXXX]
04-25 17:04:04.626 28473 28525 D RNIapModule: responseCode: 0
04-25 17:04:04.628 28473 28525 D RNIapModule: responseCode: 0
04-25 17:04:04.669 28473 28524 I ReactNativeJS: =============>response:[]
04-25 17:04:04.693 28473 28524 I ReactNativeJS: =============>response:[]

But with iOS I get the array with the datas well format.

PD1 I get the recommendation from https://medium.com/@dooboolab/react-native-in-app-purchase-121622d26b67

PD2 "Help me Obi Wan Kenobi you're my only hope"

Package.json snippet:
"dependencies": {
"react": "16.3.1",
"react-native": "0.55.3",
"react-native-iap": "^0.3.18"
},

@vadermemo @martinberbesson Hi~ Could you share your js code for itemSkus? Did you set up like below code?

export const PURCHASE_ITEMS = Platform.select({
  ios: [
    'productid_1',
    'productid_2',
  ],
  android: [
    'productid_1',
    'productid_2',
  ],
});

Also, draft app testing is no longer supported. Pleaser refer to guide. Make sure to publish your app to alpha or beta channel.

Hi @dooboolab

This is my data
const itemSkus = Platform.select({
ios: [
'com.iap.cart',
'com.iap.doublecoins'
],
android: [
'double',
'cart_1500'
],
});

Best regards

PD1 My app is in alfa version, even don't get the products.
PD2 With other npm, like react-native-billing I can get the products :(

@vadermemo this souds really bad to me.. sorry for that. It works fine in my environment. I will debug more tommorow and surely get back tommorow! Also could you try to catch the statement and see what’s appearing there?

i think i need to have a alpha release... Upload a apk with billing permission is not enough

@dooboolab Well, if there exists a something help for you, maybe is next point:

when I put the configuration on react-native-billing I putted in the resources file "string.xml" the param string name="RNB_GOOGLE_PLAY_LICENSE_KEY"
but in react-native-iap I can't see this parameter in action.

The try-catch that you required throws the next log:

  1. Change my itemsSkus

const itemSkus = Platform.select({
ios: [
'predictorcart_1500',
],
android: [
'predictorcart_1500',
'android.test.purchased',
'android.test.canceled',
'android.test.refunded',
'android.test.item_unavailable',
],
});

  1. change on componentDidMount

    async componentDidMount(){
    try {
    await RNIap.prepare();
    await this.getItems();

    }
    catch (err) {
    console.warn(err.code, err.message);
    }
    }

  2. Change the get data

    getProductDetails = async() => {
    try {
    const products = await RNIap.getProducts(itemSkus);
    console.log('=======>Products::::', products);
    this.setState({ productDetails: products });
    } catch (err) {
    console.warn(err.code, err.message);
    }
    }

  3. Put a button
    \

  4. Put the app on device
    react-native run-android --variant=release

6.Finally the log is the next:
04-26 12:53:11.335 16749 16759 I Finsky : [11707] com.google.android.finsky.billing.iab.ab.b(46): com.projectbundle: Account from first account - [uuAJBL1tLX2MAj69S-olEl331212]
04-26 12:53:11.401 226 1177 V audio_hw_primary: do_output_standby in
04-26 12:53:11.409 20362 20432 D RNIapModule: responseCode: 0
04-26 12:53:11.426 226 1177 W audio_hw_primary: do_output_standby.mode:0
04-26 12:53:11.426 226 1177 V audio_hw_primary: do_output_standby in out
04-26 12:53:11.427 1140 2106 D PowerManagerService: releaseWakeLockInternal: lock=87714678 [AudioMix], flags=0x0, total_time=3166ms
04-26 12:53:11.444 20362 20431 I ReactNativeJS: '=======>Products::::', [ { description: 'Descripción de muestra para el producto: android.test.canceled.',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: title: 'Título de muestra',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: localizedPrice: '$18.65',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: type: 'inapp',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: currency: 'MXN',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: price: '18.65',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: productId: 'android.test.canceled' },
04-26 12:53:11.444 20362 20431 I ReactNativeJS: { description: 'Descripción de muestra para el producto: android.test.item_unavailable.',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: title: 'Título de muestra',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: localizedPrice: '$18.65',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: type: 'inapp',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: currency: 'MXN',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: price: '18.65',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: productId: 'android.test.item_unavailable' },
04-26 12:53:11.444 20362 20431 I ReactNativeJS: { description: 'Descripción de muestra para el producto: android.test.purchased.',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: title: 'Título de muestra',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: localizedPrice: '$18.65',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: type: 'inapp',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: currency: 'MXN',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: price: '18.65',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: productId: 'android.test.purchased' },
04-26 12:53:11.444 20362 20431 I ReactNativeJS: { description: 'Descripción de muestra para el producto: android.test.refunded.',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: title: 'Título de muestra',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: localizedPrice: '$18.65',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: type: 'inapp',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: currency: 'MXN',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: price: '18.65',
04-26 12:53:11.444 20362 20431 I ReactNativeJS: productId: 'android.test.refunded' } ]

@martinberbesson I have an app on alpha release, even I can't get the products. I think is another thing, maybe a configuration in react-native-iap or google console.

@martinberbesson @dooboolab Incredible!!

I made another app with the same steps and the app is working on iOS and Android!!. I can`t believe it.

I don´t know which is the reason, but I think is something configuration on code or google console.

PD I was waiting 5 hours to get the correct itemSkus.
PD2 The old app not get itemsSkus even with 24 hours .
PD3 @dooboolab Now You can sleep quiet. :)
PD4 I will develop the buy process, I hope that is easy

Best regards,

@vadermemo Glad that it is working. Also, for newer iap module for android which is v3, you don't need to put anything else in string.xml.

Per #124 I think this is still occurring - at least for existing apps which it would be good to have a solution for this as well.

For anyone who's still running into this issue, you should first of all read https://stackoverflow.com/a/35132936/1374827 and ensure you've met all the requirements outlined in that post.

If that stuff is all good, check that you are calling the appropriate function. For me, I had an app where I was only using Subscription in-app purchases, but I was mistakenly calling RNIap.getProducts and of course getting back an empty array. I had to instead call RNIap.getSubscriptions and the subscriptions were then returned.

In the same vein, make sure you're calling RNIap.buySubscription if you're buying a subscription, and RNIap.buyProduct if you're buying a product.

Ok after wrestling with this, my issue turned out to be my inexperience with android. I had been messing with the package name in dev and while it ran fine on the device, the package name not being set up perfectly is why it was returning an empty array. After following these steps and these it's all looking good.

I also getting empty array,
And I am confused with https://developer.android.com/google/play/billing/billing_testing#draft_apps doc, that I need test account and add tester, so please any one can help me for this.

Thanks!

same

@bharatidudhjiya @tmjordan If you guys are facing configuration issue, I'd like you to try pure android iap project first and see if it works correctly. That would also help you understand better on android's iap sdk.

@hyochan thanks, it's a good idea. I will do that

@tmjordan This is quite old but this might help you basic setup.

thank you man @hyochan

I solved it! I am using these versions,

react-native-iap: ^4.3.0
react-native: 0.60.5

just do it like this

const itemSkus = Platform.select({
    ios: [
        '100coins' // just remove bundle id from product id
    ],
    android: [
        '100coins' // just remove bundle id from product id
    ]
});

Make Sure you have the correct package name for your application.

and in case you have changed it from react-native command. it won't still work.

You have to do it manually and then clean the project using ./gradlew clean in the android folder.

after that give it a try.

Happy Coding.

Was this page helpful?
0 / 5 - 0 ratings