安装react-native-iap后React Native应用程序无法运行
我有一个可以正常工作的 React-Native 应用程序,但需要包含应用程序内购买才能在应用程序商店中被接受。 经过一番谷歌搜索后,看起来react-native-iap几乎是唯一的选择。
第一个错误
按照安装步骤操作后此处,我在 Android Studio 中收到以下错误:
e: C:\path_to_my_project\node_modules\react-native-iap\android\src\play\java\com\dooboolab\RNIap\RNIapModule.kt: (215, 37): < strong>类型不匹配:推断类型是 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
错误日志:握手之前收到意外的数据包。
RN 和 IAP 版本
React-Native 版本:0.63.4
React-native-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))
}
...
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))
}
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
skuList.add(skuArr.getString(i).orEmpty())
请尝试添加 .orEmpty()
skuList.add(skuArr.getString(i).orEmpty())
please try added .orEmpty()