Skip to content

FIXED: Android build fails: 'val' cannot be reassigned errors in MenuView.kt and MenuViewManagerBase.kt when using Kotlin 2.x #1186

@Bifiku

Description

@Bifiku

After updating to Kotlin 2.x and AGP 8.8, Android build fails for @react-native-menu/menu with:
error: MenuView.kt: ‘val’ cannot be reassigned
error: MenuViewManagerBase.kt: ‘val’ cannot be reassigned

This happens because hitSlopRect and overflow are val properties and can’t be reassigned directly anymore.

Quick fix

Replaced property assignments with setter calls:

// Before 
// node_modules/@react-native-menu/menu/android/src/main/java/com/reactnativemenu/MenuView.kt
super.hitSlopRect = value

// node_modules/@react-native-menu/menu/android/src/main/java/com/reactnativemenu/MenuViewManagerBase.kt
view.hitSlopRect = rect
view.overflow = overflow

// After 
// node_modules/@react-native-menu/menu/android/src/main/java/com/reactnativemenu/MenuView.kt
super.setHitSlopRect(value)

//node_modules/@react-native-menu/menu/android/src/main/java/com/reactnativemenu/MenuViewManagerBase.kt
view.setHitSlopRect(rect)
view.setOverflow(overflow)

I’ve attached a small patch that fixes the build on Kotlin 2.x.
It replaces invalid val reassignments with setter calls.
Just apply it with patch-package until it’s merged upstream.

@react-native-menu+menu+2.0.0.patch

Environment
• @react-native-menu/menu: 2.x
• React Native: 0.76.x
• Gradle: 8.13
• Android Gradle Plugin: 8.8.2
• Kotlin: 2.x
• compileSdk: 36

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions