mrousavy / react-native-mmkv

⚡️ The fastest key/value storage for React Native. ~30x faster than AsyncStorage!
https://mrousavy.com
MIT License
6.2k stars 259 forks source link

Compilation fails with React Native 0.75 and Gradle 8.8 #748

Closed JJ-Dynamite closed 1 month ago

JJ-Dynamite commented 1 month ago

Environment

Description of the issue

When trying to build the Android app with React Native 0.75 and react-native-mmkv 2.12.1, the compilation fails at the :react-native-mmkv:compileDebugJavaWithJavac task.

Error message

[react-native-mmkv] Thank you for using react-native-mmkv ❤️
[react-native-mmkv] If you enjoy using react-native-mmkv, please consider sponsoring this project: https://github.com/sponsors/mrousavy
> Configure project :react-native-reanimated
Android gradle plugin: 8.5.0
Gradle: 8.8
> Task :react-native-mmkv:compileDebugJavaWithJavac FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

Steps to reproduce

  1. Set up a new React Native 0.75 project
  2. Install react-native-mmkv@3.0.2
  3. Try to build the Android app

Expected behavior

The Android app should build successfully.

Actual behavior

The build fails at the :react-native-mmkv:compileDebugJavaWithJavac task.

Additional context

This issue seems to be related to compatibility with the latest Gradle and Android Gradle Plugin versions used in React Native 0.75. It might require updates to the build scripts or configurations in react-native-mmkv to support these newer versions.

Possible solutions

Any assistance or guidance on resolving this issue would be greatly appreciated. Thank you!

maintenance-hans[bot] commented 1 month ago

Guten Tag, Hans here! 🍻

Thanks for reporting your issue. It looks like you’re facing a compilation problem with React Native 0.75 and Gradle 8.8 while using react-native-mmkv. However, there are a few points to clarify:

  1. You mentioned react-native-mmkv version 2.12.1, but your environment specifies version 3.0.2. Please confirm which version you are using.
  2. It would help if you could provide the exact error logs when the build fails, especially ones that indicate what's going wrong. You can get the logs using adb logcat for Android.

Mrousavy can certainly take a look once we have more information! If you enjoy using react-native-mmkv, please consider sponsoring this project by visiting this link. It really helps keep the project going!

Note: If you think I made a mistake, please ping @mrousavy to take a look.

JJ-Dynamite commented 1 month ago

Hello Hans! 🍻

Thank you for your kind response and for taking the time to address this issue. I greatly appreciate your help.

You're right, I need to clarify a few points:

  1. Regarding the version of react-native-mmkv: In my package.json, it's actually version 3.0.2. Here's the relevant excerpt:

    "dependencies": {
    // ...
    "react-native-mmkv": "^3.0.2",
    // ...
    }
  2. As for the exact error logs :

    
    > Task :react-native-mmkv:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.8/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation. 289 actionable tasks: 23 executed, 266 up-to-date <-------------> 0% WAITING

IDLE IDLE

info 💡 Tip: Make sure that you have set up your development environment correctly, by running npx react-native doctor. To read more about doctor command visit: https://github.com/react-native-community/cli/blob/main/packages/cli-doctor/README.md#doctor

/Users/bonderconnect/Bonder/App/node_modules/react-native-mmkv/android/src/main/java/com/mrousavy/mmkv/MmkvPlatformContextModule.java:7: error: cannot find symbol public class MmkvPlatformContextModule extends NativeMmkvPlatformContextSpec { ^ symbol: class NativeMmkvPlatformContextSpec /Users/bonderconnect/Bonder/App/node_modules/react-native-mmkv/android/src/main/java/com/mrousavy/mmkv/MmkvPlatformContextModule.java:15: error: method does not override or implement a method from a supertype @Override ^ /Users/bonderconnect/Bonder/App/node_modules/react-native-mmkv/android/src/main/java/com/mrousavy/mmkv/MmkvPlatformContextModule.java:21: error: method does not override or implement a method from a supertype @Override ^ /Users/bonderconnect/Bonder/App/node_modules/react-native-mmkv/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java:19: error: cannot find symbol if (name.equals(MmkvPlatformContextModule.NAME)) { ^ symbol: variable NAME location: class MmkvPlatformContextModule /Users/bonderconnect/Bonder/App/node_modules/react-native-mmkv/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java:20: error: incompatible types: MmkvPlatformContextModule cannot be converted to NativeModule return new MmkvPlatformContextModule(reactContext); ^ /Users/bonderconnect/Bonder/App/node_modules/react-native-mmkv/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java:31: error: cannot find symbol MmkvPlatformContextModule.NAME, ^ symbol: variable NAME location: class MmkvPlatformContextModule /Users/bonderconnect/Bonder/App/node_modules/react-native-mmkv/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java:33: error: cannot find symbol MmkvPlatformContextModule.NAME, ^ symbol: variable NAME location: class MmkvPlatformContextModule /Users/bonderconnect/Bonder/App/node_modules/react-native-mmkv/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java:34: error: cannot find symbol MmkvPlatformContextModule.NAME, ^ symbol: variable NAME location: class MmkvPlatformContextModule Note: /Users/bonderconnect/Bonder/App/node_modules/react-native-mmkv/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. 8 errors

FAILURE: Build failed with an exception.

BUILD FAILED in 4s error Failed to install the app. Command failed with exit code 1: ./gradlew app:installDebug -PreactNativeDevServerPort=8081 /Users/bonderconnect/Bonder/App/node_modules/react-native-mmkv/android/src/main/java/com/mrousavy/mmkv/MmkvPlatformContextModule.java:7: error: cannot find symbol public class MmkvPlatformContextModule extends NativeMmkvPlatformContextSpec { ^ symbol: class NativeMmkvPlatformContextSpec /Users/bonderconnect/Bonder/App/node_modules/react-native-mmkv/android/src/main/java/com/mrousavy/mmkv/MmkvPlatformContextModule.java:15: error: method does not override or implement a method from a supertype @Override ^ /Users/bonderconnect/Bonder/App/node_modules/react-native-mmkv/android/src/main/java/com/mrousavy/mmkv/MmkvPlatformContextModule.java:21: error: method does not override or implement a method from a supertype @Override ^ /Users/bonderconnect/Bonder/App/node_modules/react-native-mmkv/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java:19: error: cannot find symbol if (name.equals(MmkvPlatformContextModule.NAME)) { ^ symbol: variable NAME location: class MmkvPlatformContextModule /Users/bonderconnect/Bonder/App/node_modules/react-native-mmkv/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java:20: error: incompatible types: MmkvPlatformContextModule cannot be converted to NativeModule return new MmkvPlatformContextModule(reactContext); ^ /Users/bonderconnect/Bonder/App/node_modules/react-native-mmkv/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java:31: error: cannot find symbol MmkvPlatformContextModule.NAME, ^ symbol: variable NAME location: class MmkvPlatformContextModule /Users/bonderconnect/Bonder/App/node_modules/react-native-mmkv/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java:33: error: cannot find symbol MmkvPlatformContextModule.NAME, ^ symbol: variable NAME location: class MmkvPlatformContextModule /Users/bonderconnect/Bonder/App/node_modules/react-native-mmkv/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java:34: error: cannot find symbol MmkvPlatformContextModule.NAME, ^ symbol: variable NAME location: class MmkvPlatformContextModule Note: /Users/bonderconnect/Bonder/App/node_modules/react-native-mmkv/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. 8 errors FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':react-native-mmkv:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details. * Try: Run with --info option to get more log output. Run with --scan to get full insights. BUILD FAILED in 4s. info Run CLI with --verbose flag for more details.

  1. Thank you for pointing out the opportunity to support the project. I will definitely consider contributing, as react-native-mmkv is a valuable tool for my development.

    Thank you again for your support and patience.

maintenance-hans[bot] commented 1 month ago
it ain't much, but it's honest work
amutsch commented 1 month ago

Good Evening JJ.

react-native-mmkv is built only for the new architecture. React native 75 does not have that enabled by default.

This line in the error log tells me you are not running new architecture /Users/bonderconnect/Bonder/App/node_modules/react-native-mmkv/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java:20: error: incompatible types: MmkvPlatformContextModule cannot be converted to NativeModule

Options for moving forward. Downgrade to react-native-mmkv 2.12.x Enable the new architecture for react native and stay on 3.0.2

Thanks

JJ-Dynamite commented 1 month ago

Thank you for bringing this to my attention. By default, the new architecture is not enabled. To activate it, please follow these steps:

  1. Android Configuration:

    • Navigate to android/gradle.properties
    • Set newArchEnabled=true
  2. iOS Configuration:

    • Open ios/Podfile
    • Add use_frameworks! :linkage => :static at the top of the file
    • Modify the React Native path to include Fabric: use_react_native!(:path => config[:reactNativePath], :fabric_enabled => true)
  3. Rebuild Your Project:

    • For Android:
      cd android
      ./gradlew clean
      cd ..
      yarn android
    • For iOS:
      cd ios
      pod install
      cd ..
      yarn ios

After implementing these changes, the new architecture should be successfully enabled. Please ensure you follow each step carefully to avoid any potential issues during the rebuild process.

JJ-Dynamite commented 1 month ago

Compilation fails with React Native 0.75 and Gradle 8.8 issue fixed