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
After updating to Kotlin 2.x and AGP 8.8, Android build fails for
@react-native-menu/menuwith:error: MenuView.kt: ‘val’ cannot be reassigned
error: MenuViewManagerBase.kt: ‘val’ cannot be reassigned
This happens because
hitSlopRectandoverflowarevalproperties and can’t be reassigned directly anymore.Quick fix
Replaced property assignments with setter calls:
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