react-native-video: [BUG]: :react-native-video:compileDebugJavaWithJavac because error: switch expressions are not supported in -source 11

Version

6.7.0

What platforms are you having the problem on?

Android

System Version

Android

On what device are you experiencing the issue?

Real device

Architecture

New architecture with interop layer

What happened?

A strange bug caused by a “missing feature of java” cause this :react-native-video:compileDebugJavaWithJavac error: /exoplayer/ReactExoplayerView.java:522: error: switch expressions are not supported in -source 11 and tell me to: (use -source 14 or higher to enable switch rules)

I use Azul Zulu JDK 17 on a iMac. So it’s really strange that is complaining about a source 11 error (assuming is intending Java 11)

java -version

openjdk version “17.0.11” 2024-04-16 LTS OpenJDK Runtime Environment Zulu17.50+19-CA (build 17.0.11+9-LTS) OpenJDK 64-Bit Server VM Zulu17.50+19-CA (build 17.0.11+9-LTS, mixed mode, sharing)

No bug has been reported nor in react-native-video nor in ExoPlayer repo

Reproduction Link

repository link

Reproduction

Step to reproduce this bug are: Use react-native-video Run react-native run-android, with Azul Zulu JDK 17

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 19

Most upvoted comments

I hade same issue, i’m not a fan of patch, the workaround that work for me was explicit define java version on android/build.gradle

I add this peace of code

subprojects {
    afterEvaluate { project ->
        if (project.hasProperty("android")) {
            project.android.compileOptions {
                sourceCompatibility JavaVersion.VERSION_14
                targetCompatibility JavaVersion.VERSION_14
            }
        }
    }
}

i fixed it with downgrade to “react-native-video”: “6.6.4”

This fixed for me:

Updated(In ReactExoplayerView):

            float speed = switch (which) {
                case 0 -> 0.5f;
                case 2 -> 1.5f;
                case 3 -> 2.0f;
                default -> 1.0f;
            };

TO

            switch (which) {
                case 0:
                    speed = 0.5f;
                    break;
                case 2:
                    speed = 1.5f;
                    break;
                case 3:
                    speed = 2.0f;
                    break;
                default:
                    speed = 1.0f;
                    break;
            }

Then did: npx patch-package react-native-video

I’ve patched this file node_modules/react-native-video/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java

-            float speed = switch (which) {
-                case 0 -> 0.5f;
-                case 2 -> 1.5f;
-                case 3 -> 2.0f;
-                default -> 1.0f;
-            };
+            float speed;
+            switch (which) {
+                case 0:
+                    speed = 0.5f;
+                    break;
+                case 2:
+                    speed = 1.5f;
+                    break;
+                case 3:
+                    speed = 2.0f;
+                    break;
+                default:
+                    speed = 1.0f;
+                    break;
+            }