javaandroidreactjsreact-nativecompiler-errors

Error « switch rules are not supported in -source 11 » when compiling with react-native-reanimated


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 :

  1. 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
     }
    }
    
  2. Cleaning and reconstruction :

Questions :

Thanks in advance !


Solution

  • 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 "^".