Skip to content

fix(android): use reactApplicationContext.currentActivity to compile with Kotlin 2.2 (React Native 0.87+) - #228

Open
kmy-n wants to merge 1 commit into
xmartlabs:mainfrom
kmy-n:fix/android-current-activity-kotlin-2-2
Open

kmy-n wants to merge 1 commit into
xmartlabs:mainfrom
kmy-n:fix/android-current-activity-kotlin-2-2

Conversation

@kmy-n

@kmy-n kmy-n commented Oct 20, 2026

Copy link
Copy Markdown

Use reactApplicationContext.currentActivity to compile with Kotlin 2.2 (React Native 0.87+)

🔄 Type of change:

  • ✨Feature/chore
  • ♻️ Refactor
  • 🔧 Bugfixes

✏️ Description:

The Android module fails to compile on React Native 0.87 and later. From 0.87, the React Native Gradle plugin brings in Kotlin 2.2.0, and the compiler rejects line 94 of LineLoginModule.kt:

e: file:///.../android/src/main/java/com/xmartlabs/line/LineLoginModule.kt:94:24 Function invocation 'getCurrentActivity()' expected.

currentActivity on that line resolves to ReactContextBaseJavaModule.getCurrentActivity(). It is a Kotlin function, but the module reaches it through the Java codegen class NativeLineLoginSpec, so Kotlin treats it as a synthetic property. Kotlin 2.1 reports this only as a warning (output from Kotlin 2.1.20 with the current main):

w: .../LineLoginModule.kt:94:24 This synthetic property is based on the getter function 'fun getCurrentActivity(): Activity?' from Kotlin. In the future, synthetic properties will be available only if the base getter function came from Java. Consider replacing this property access with a 'getCurrentActivity()' function call.

Kotlin 2.2 turns it into the error above (KT-72272). The getter has also been deprecated since React Native 0.80:

w: .../LineLoginModule.kt:94:24 'val currentActivity: Activity?' is deprecated. Deprecated in 0.80.0. Use getReactApplicationContext().getCurrentActivity() instead.

This PR uses reactApplicationContext.currentActivity, the replacement named in that deprecation message. In React Native, the deprecated getter is implemented as return reactApplicationContext.currentActivity, so the returned activity is the same and the login flow does not change. ReactContext#getCurrentActivity() existed before the 0.80 deprecation, so the minimum supported React Native version does not change either.


🎥 Screen record:

N/A — build fix with no UI change. The login flow was checked on an emulator (see Notes).


📌 Notes:

Verified locally with the example app on top of the current main (8e3a127): Expo SDK 57, React Native 0.86.3, AGP 8.12.0, Gradle 9.3.1, JDK 17.

  • ./gradlew :xmartlabs_react-native-line:compileDebugKotlin:

    Kotlin Before this PR After this PR
    2.1.20 (default for React Native 0.86) ✅ Builds, with the 2 warnings above on line 94 ✅ Builds, no warnings in LineLoginModule.kt
    2.2.0 ❌ Function invocation 'getCurrentActivity()' expected ✅ Builds, no warnings in LineLoginModule.kt

    To build the example with Kotlin 2.2.0, I temporarily changed the generated example/android/build.gradle to classpath('org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.0'). This change is not part of the PR.

  • ./gradlew assembleRelease -PreactNativeArchitectures=arm64-v8a succeeds with the default Kotlin 2.1.20.

  • With that release build on a Pixel 9a emulator (Android 16, API 36, LINE app not installed):

    • Tapping Log In starts LineAuthenticationActivity from the activity obtained on the changed line, and the web login opens in Chrome.
    • Pressing back cancels the login. Line.login() rejects with LOGIN_CANCELLED, and the example shows its "Failed to log in" alert, the same as before this change.
  • I also checked an app on React Native 0.88.0 (Kotlin 2.2.0, AGP 9.2.1, Gradle 9.4.1). Without this change the module fails with the same error, and with it the module compiles.

  • Until a release includes this fix, apps on React Native 0.87+ can work around the error by compiling only this module with the Kotlin 2.1 language version:

    // android/build.gradle
    project(':xmartlabs_react-native-line') {
        tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
            compilerOptions.languageVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_1
        }
    }

✔️Tasks:

  • Replace currentActivity with reactApplicationContext.currentActivity in LineLoginModule.login() (android/src/main/java/com/xmartlabs/line/LineLoginModule.kt).

⚠️ Warnings:


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.

1 participant