Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
diessetechnology opened this issue Oct 23, 2024 · 12 comments
Labels

Comments

@diessetechnology
Copy link

diessetechnology commented Oct 23, 2024

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

Copy link

github-actions bot commented Oct 23, 2024

Previous bot comment (click to expand)

Thank you for your issue report. Please note that the following information is missing or incomplete:

  • reproduction link

Please update your issue with this information to help us address it more effectively.

Note: issues without complete information have a lower priority

There is a newer version of the library available. You are using version ^6.7.0, while the latest stable version is 6.7.0. Please update to the latest version and check if the issue still exists.

Note: If the issue still exists, please update the issue report with the latest information.

Copy link

Thank you for your issue report. Please note that the following information is missing or incomplete:

  • reproduction link

Please update your issue with this information to help us address it more effectively.

Note: issues without complete information have a lower priority

@freeboub
Copy link
Collaborator

which react native version do you use ?

@freeboub
Copy link
Collaborator

just for information, your comment is right:
The syntax you provided, which uses the enhanced switch expression with the -> arrow notation and returning a value, is supported starting from Java 12 under the preview feature, and it became a standard feature in Java 14.

Here’s a summary of the relevant Java versions:

Java 12: Introduced the new switch expression as a preview feature.
Java 13: Continued the preview of this feature with some refinements.
Java 14: The switch expression became a standard feature.
So, starting from Java 14, this syntax is fully supported and no longer requires enabling preview features.

@diessetechnology
Copy link
Author

React native is version 0.71.7. And so, it seems to be a error related directly to ExoPlayer. But it affects react-native-video in the matter that i can't compile app for android. Did i have to open a issue to google/ExoPlayer repo?
Because is a thing that is abnormal to happen with JDK 17...and now i'm questioning myself if is a error that happen in non-react native apps that use ExoPlayer...

Like i said, no issue about this i've found online, nor on react-native-video nor in Exoplayer repos. And neither in StackOverflow like sites...So i deduce that is a new error of some update in react-native-video or ExoPlayer

@Ajmal0197
Copy link

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

@diessetechnology
Copy link
Author

Is solved. Thank you very much for help @Ajmal0197

@diessetechnology
Copy link
Author

I reopen this because you can track the fix for package. I can confirm that the solution is that of the user i thanked. Thanks again to everyone.

@lopesboa
Copy link

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
            }
        }
    }
}

@iphonic
Copy link

iphonic commented Nov 5, 2024

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
            }
        }
    }
}

This is a better solution.

@freeboub
Copy link
Collaborator

freeboub commented Nov 23, 2024

did you try to put

sourceCompatibility JavaVersion.VERSION_14
targetCompatibility JavaVersion.VERSION_14

directly in the package ? I think it would be a better solution ?!

@mina2310
Copy link

mina2310 commented Nov 25, 2024

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;
+            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants