Skip to content

fix(android): use reactApplicationContext.currentActivity for RN 0.87 - #16

Merged
Mhp23 merged 1 commit into
mhpdev-com:mainfrom
jellebreuer:fix/rn-087-current-activity
Sep 9, 2026
Merged

Mhp23 merged 1 commit into
mhpdev-com:mainfrom
jellebreuer:fix/rn-087-current-activity

Conversation

@jellebreuer

Copy link
Copy Markdown

Fixes #15.

On React Native 0.87 the Android build fails with:

e: .../com/speech/RNSpeechModule.kt:733:22 Function invocation 'getCurrentActivity()' expected.

Cause. ReactContextBaseJavaModule was converted to Kotlin in 0.87, so getCurrentActivity() is now declared as a protected fun rather than a Java getter. Kotlin's synthetic property access only applies to Java getters, so currentActivity no longer resolves and the compiler demands an explicit call.

Fix. The method has also been deprecated since 0.80.0, and its annotation names the replacement directly:

// ReactContextBaseJavaModule.kt
@Deprecated(
    "Deprecated in 0.80.0. Use getReactApplicationContext().getCurrentActivity() instead.",
    ReplaceWith("reactApplicationContext.currentActivity"),
)
protected fun getCurrentActivity(): Activity? = reactApplicationContext.currentActivity

Using that replacement fixes the build and removes the deprecation warning at the same time, which calling getCurrentActivity() explicitly would not.

Compatibility. This should be safe across React Native versions rather than trading one break for another. Both accessors it goes through are still Java getters — BaseJavaModule.getReactApplicationContext() is protected final and ReactContext.getCurrentActivity() is public @Nullable — so synthetic property access remains valid on older releases too. reactApplicationContext is also what the deprecated method itself delegates to, so behaviour is unchanged.

Verification. Built against React Native 0.87.1 with the New Architecture on Android (compileSdk 37, AGP 9, Gradle 9.4.1): :mhpdev_react-native-speech:compileDebugKotlin and a full :app:assembleDebug both succeed, with no deprecation warning. Text-to-speech works on device. Only openVoiceDataInstaller is touched.

ReactContextBaseJavaModule was converted to Kotlin, so getCurrentActivity() is
now a fun rather than a Java getter and Kotlin synthetic property access no
longer resolves, failing the build with:

  e: RNSpeechModule.kt:733:22 Function invocation 'getCurrentActivity()' expected.

It has also been deprecated since 0.80.0 in favour of
reactApplicationContext.currentActivity, which is what its ReplaceWith names.
Both accessors it goes through are still Java getters, so this compiles on old
and new React Native alike and drops a deprecation warning.

Fixes mhpdev-com#15
@Mhp23

Mhp23 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

LGTM! Thanks for the PR.

@Mhp23
Mhp23 merged commit d97118c into mhpdev-com:main Sep 9, 2026
@Mhp23
Mhp23 requested review from Mhp23 and removed request for Mhp23 September 9, 2026 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Not compatible with RN 0.87.1

2 participants