安装React Native iap后,React Native应用程序无法运行



我有一个正在运行的React Native应用程序,但需要包括应用程序内购买才能在应用商店中接受。在谷歌上搜索一下后,react原生iap似乎是唯一的选择。

第一个错误

按照这里的安装步骤后,我在Android Studio中得到以下错误:

e:C:\path_to_my_project\node_modules\react native iap\android\src\play\java\com\dooboolab\RNIap\RNIap Module.kt:(215,37(:类型不匹配:推断类型为String?但字符串应为

如链接中所述,错误被抛出到RNIapModule.kt文件中,我将从下面链接一段摘录(完整的代码使我超过了字符限制,但自安装以来我没有更改它(。

我取消了指令中的所有更改,似乎唯一阻止我出现此错误的是没有在android/app/build.gradle中添加存储规范,当然,这也会出错,我想就在上面提到的错误之前。

第二个错误

在构建部分,我看到了另一个错误:

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-iap:compilePlayDebugKotlin'.
> Compilation error. See log for more details

错误日志:An unexpected packet was received before the handshake.


RN和IAP版本

React Native版本:0.63.4

react原生iap版本:^8.0.5


完整依赖项列表

"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"
},

来自RNIapModule.kt的代码

只是抛出错误的功能块:

...
@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))
}
...

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

请尝试added.orEmpty((

最新更新