I'm working on a React Native application and I'm getting an error when compiling Android linked to the react-native-reanimated library or the Java version. Here are the details :
My versions :
This is the error I get when I try to build :
/Users/me/Documents/Projects/my-project/node_modules/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/NodesManager.java:440: error: switch rules are not supported in -source 11 case "opacity" -> { ^ (use -source 14 or higher to enable switch rules)
/Users/me/Documents/Projects/my-project/node_modules/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java:356: error: pattern matching in instanceof is not supported in -source 11 if (props.get(Snapshot.TRANSFORM_MATRIX) instanceof ReadableNativeArray matrixArray) { ^ (use -source 16 or higher to enable pattern matching in instanceof)
Steps I tried :
Gradle configuration : I added this in android/app/build.gradle, but nothing changed, it didn't fix my problem :
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}
Cleaning and reconstruction :
I ran ./gradlew clean in the android directory.
I rebuilt with npx react-native run-android.
Questions :
How can this problem be resolved so that the project uses Java 17?
Is it possible that incompatibilities in my dependencies are preventing the Java version from being updated correctly?
Is there a specific version of the library that could correct this?
Thanks in advance !
I fixed it, just change on my package.json my version of react-native-reanimated :
"^3.9.0-rc.1"
to
"3.9.0-rc.1"
I delete the "^".