Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: android build error with React Native 0.76 #2872

Merged
merged 1 commit into from
Nov 1, 2024
Merged

Conversation

mlazari
Copy link
Contributor

@mlazari mlazari commented Oct 27, 2024

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: facebook/react-native@de73e44#diff-74cbd5a9d82e4c21dbc37dd72a92e31542e574dc6425d2454c3ce53e71e08bbeR31 but in react-native-iap it is called with a nullable string: https://github.com/hyochan/react-native-iap/blob/12.15.6/android/src/main/java/com/dooboolab/rniap/PromiseUtlis.kt#L40.

This change updates that call to use an empty string "" for code if for some reason it's null.

Fixes #2871

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: facebook/react-native@de73e44#diff-74cbd5a9d82e4c21dbc37dd72a92e31542e574dc6425d2454c3ce53e71e08bbeR31 but in react-native-iap it is called with a nullable string: https://github.com/hyochan/react-native-iap/blob/12.15.6/android/src/main/java/com/dooboolab/rniap/PromiseUtlis.kt#L40.

This change updates that call to use an empty string "" for code if for some reason it's null.

Fixes hyochan#2871
Copy link
Owner

@hyochan hyochan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

However, I am wondering why the error code could become null 🤔 (Of course, I’m referring to the detailed PR description you provided as well.)

@hyochan hyochan added the 🥢 typo Typo label Nov 1, 2024
@hyochan hyochan merged commit 38ac100 into hyochan:main Nov 1, 2024
4 checks passed
@mlazari
Copy link
Contributor Author

mlazari commented Nov 1, 2024

@hyochan You're right, I just reviewed all the places where safeReject is called and didn't find any place where it could be called with a null value. Not sure why it was declared as a nullable String in that case. Maybe it should just be changed to a non-nullable String.

mlazari added a commit to mlazari/react-native-iap that referenced this pull request Nov 1, 2024
The reject method of Promise class became non-nullable in React Native 0.76 after rewriting it from Java to Kotlin. We fixed it being called with a nullable value in hyochan#2872 by providing and empty string as a fallback if it happens to be null. But after more investigation it seems like it's not called with a value that could be null anywhere in the code, so a better solution would be to just update the type of the `code` parameter to be non-nullable.
@mlazari
Copy link
Contributor Author

mlazari commented Nov 1, 2024

@hyochan I opened a new PR here #2875 if you prefer that solution instead.

hyochan pushed a commit that referenced this pull request Nov 4, 2024
The reject method of Promise class became non-nullable in React Native
0.76 after rewriting it from Java to Kotlin. We fixed it being called
with a nullable value in
#2872 by providing and
empty string as a fallback if it happens to be null. But after more
investigation it seems like it's not called with a value that could be
null anywhere in the code, so a better solution would be to just update
the type of the `code` parameter to be non-nullable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖 android Related to android 👷‍♀️ build Build issue 🥢 typo Typo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type mismatch: inferred type is String? but String was expected
2 participants