3

I have an otherwise working React-Native app but need to include in-app purchases for it to be accepted on the app store. After a little Googling, it looks like react-native-iap is pretty much the only option.

First Error

After following the installation steps HERE, I get the following error in Android Studio:

e: C:\path_to_my_project\node_modules\react-native-iap\android\src\play\java\com\dooboolab\RNIap\RNIapModule.kt: (215, 37): Type mismatch: inferred type is String? but String was expected

As stated in the link, the error is being thrown in the RNIapModule.kt file, which I will link an excerpt from below (the full code pushes me over the character limit, but I have not changed it since installation).

I undid all the changes from the instructions, and it seems the only thing that prevents me from getting this error is not adding the store specification in android/app/build.gradle, which of course, also errors out, I assume just before the error mention above.

Second Error

Looking higher up in build section, I see another error:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-iap:compilePlayDebugKotlin'.

> Compilation error. See log for more details

Error log: An unexpected packet was received before the handshake.


RN and IAP versions

React-Native version: 0.63.4

react-native-iap version: ^8.0.5


Full dependency list

  "dependencies": {
    "@react-native-async-storage/async-storage": "^1.13.2",
    "@react-native-community/checkbox": "^0.5.7",
    "@react-native-community/masked-view": "^0.1.11",
    "@react-native-community/netinfo": "^6.0.0",
    "@react-native-community/progress-bar-android": "^1.0.4",
    "@react-native-community/progress-view": "^1.2.3",
    "@reduxjs/toolkit": "^1.4.0",
    "@thecodingmachine/redux-toolkit-wrapper": "1.3.0",
    "axios": "^0.21.1",
    "buffer": "^6.0.3",
    "date-fns": "^2.19.0",
    "es6-symbol": "^3.1.3",
    "flipper-plugin-react-native-inspect-json-client": "^0.1.2",
    "formik": "^2.1.4",
    "i18next": "^19.8.2",
    "lottie-ios": "3.1.8",
    "lottie-react-native": "4.0.2",
    "moment": "^2.29.1",
    "prop-types": "^15.7.2",
    "ramda": "^0.27.1",
    "react": "16.13.1",
    "react-i18next": "^11.7.3",
    "react-native": "0.63.4",
    "react-native-app-intro-slider": "^3.0.0",
    "react-native-appearance": "^0.3.4",
    "react-native-chart-kit": "^6.10.1",
    "react-native-charts-wrapper": "^0.5.7",
    "react-native-copilot": "^2.5.0",
    "react-native-dotenv": "^0.2.0",
    "react-native-flipper": "^0.130.0",
    "react-native-gesture-handler": "^1.10.3",
    "react-native-iap": "^8.0.5",
    "react-native-image-crop-picker": "^0.35.3",
    "react-native-image-picker": "^3.1.4",
    "react-native-iphone-x-helper": "^1.3.1",
    "react-native-map-link": "^2.7.25",
    "react-native-material-menu": "^1.2.0",
    "react-native-modal": "^11.7.0",
    "react-native-permissions": "^3.2.0",
    "react-native-picker-select": "^6 P.5.0",
    "react-native-progress": "^5.0.0",
    "react-native-prompt-android": "^1.1.0",
    "react-native-reanimated": "^2.3.0",
    "react-native-safe-area-context": "^3.2.0",
    "react-native-screens": "^3.3.0",
    "react-native-size-matters": "^0.3.0",
    "react-native-sqlite-storage": "^5.0.0",
    "react-native-svg": "^12.1.0",
    "react-native-template-": "thecodingmachine/react-native-boilerplate",
    "react-native-toast-message": "^1.4.9",
    "react-native-video": "^5.1.1",
    "react-navigation": "^3.11.2",
    "react-redux": "^7.2.1",
    "redux": "^4.0.5",
    "redux-flipper": "^1.4.2",
    "redux-logger": "^3.0.6",
    "redux-persist": "^6.0.0",
    "redux-saga": "^1.0.2",
    "reduxsauce": "^1.0.1",
    "utf8": "^3.0.0",
    "yup": "^0.28.1"
  },
  "devDependencies": {
    "@babel/core": "^7.8.4",
    "@babel/plugin-proposal-decorators": "^7.13.5",
    "@babel/runtime": "^7.8.4",
    "@react-native-community/eslint-config": "^1.1.0",
    "babel-jest": "^25.1.0",
    "babel-plugin-ignite-ignore-reactotron": "^0.3.0",
    "eslint": "^6.5.1",
    "eslint-config-prettier": "^4.1.0",
    "eslint-config-standard": "^12.0.0",
    "eslint-plugin-import": "^2.16.0",
    "eslint-plugin-node": "^8.0.1",
    "eslint-plugin-prettier": "^3.0.1",
    "eslint-plugin-promise": "^4.0.1",
    "eslint-plugin-react": "^7.12.4",
    "eslint-plugin-react-native": "^3.6.0",
    "eslint-plugin-standard": "^4.0.0",
    "jest": "^25.1.0",
    "metro-react-native-babel-preset": "^0.59.0",
    "prettier": "^1.16.4",
    "react-native-rename": "^2.4.1",
    "react-test-renderer": "16.13.1",
    "reactotron-react-native": "^4.0.2",
    "reactotron-redux": "^3.1.2",
    "reactotron-redux-saga": "^4.2.3",
    "seamless-immutable": "^7.1.4",
    "seamless-immutable-mergers": "^7.1.0"
  },

Code from RNIapModule.kt

Just the function block where the error was thrown:

...
   @ReactMethod
    fun getItemsByType(type: String?, skuArr: ReadableArray, promise: Promise) {
        ensureConnection(
            promise,
            object : EnsureConnectionCallback {
                override fun run(billingClient: BillingClient) {
                    val skuList = ArrayList<String>()
                    for (i in 0 until skuArr.size()) {
                        skuList.add(skuArr.getString(i))
                    }
...
Ash West
  • 79
  • 9
  • 1
    Did you solve this issue? – Rajendran Nadar Mar 14 '22 at 21:35
  • Not exactly. I wasn't able to get the IAP library working, but I found a different library to use instead. It's called RevenueCat. You can check them out [HERE](https://www.revenuecat.com/). I also found [THIS VIDEO](https://www.youtube.com/watch?v=IbviHzKHDXY) to be super helpful (although some of the code is a little outdated). – Ash West Mar 18 '22 at 23:25
  • 1
    I used expo in app purchases that is updated and easy to use – Rajendran Nadar Mar 19 '22 at 06:03
  • 1
    I wish I had that option. The original developer on this project decided to forgo expo from the start. – Ash West Mar 21 '22 at 21:38

1 Answers1

1

skuList.add(skuArr.getString(i).orEmpty())

please try added .orEmpty()

Zevi L.
  • 131
  • 2
  • 4
  • This works, but what does the code actually do? Can you explain it please. – redberry May 31 '22 at 07:34
  • 1
    .add() only accept a string. please refer the document https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/or-empty.html – Zevi L. Jun 16 '22 at 18:12