From cfa12fc68f877494f4f65f15defd60a4877dea0d Mon Sep 17 00:00:00 2001 From: Mihai Lazari Date: Sun, 27 Oct 2024 21:35:49 +0200 Subject: [PATCH] fix: android build error with React Native 0.76 When using React Native 0.76 the Android build fails with an error: ``` java/com/dooboolab/RNIap/PromiseUtlis.kt:40:21 Type mismatch: inferred type is String? but String was expected ``` The issue seems to be caused by the fact that in RN 0.76 the Promise class was rewritten from Java to Kotlin and the code parameter of the reject method is a non-nullable String now: https://github.com/facebook/react-native/commit/de73e44569fd2932fe5683f7a392f37d866e5d35#diff-74cbd5a9d82e4c21dbc37dd72a92e31542e574dc6425d2454c3ce53e71e08bbeR31 but in react-native-iap it is called with a nullable string. This change updates that call to use an empty string "" for code if for some reason it's null. Fixes https://github.com/hyochan/react-native-iap/issues/2871 --- android/src/main/java/com/dooboolab/rniap/PromiseUtlis.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/java/com/dooboolab/rniap/PromiseUtlis.kt b/android/src/main/java/com/dooboolab/rniap/PromiseUtlis.kt index c1bc5afde..ffaa96931 100644 --- a/android/src/main/java/com/dooboolab/rniap/PromiseUtlis.kt +++ b/android/src/main/java/com/dooboolab/rniap/PromiseUtlis.kt @@ -37,7 +37,7 @@ fun Promise.safeReject( throwable: Throwable?, ) { try { - this.reject(code, message, throwable) + this.reject(code ?: "", message, throwable) } catch (oce: ObjectAlreadyConsumedException) { Log.d(TAG, "Already consumed ${oce.message}") }