TheWidlarzGroup / react-native-video

A <Video /> component for react-native
https://docs.thewidlarzgroup.com/react-native-video/
MIT License
7.22k stars 2.9k forks source link

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

Open diessetechnology opened 1 month ago

diessetechnology commented 1 month ago

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

github-actions[bot] commented 1 month ago
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.
github-actions[bot] commented 1 month ago

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

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

Note: issues without complete information have a lower priority

freeboub commented 4 weeks ago

which react native version do you use ?

freeboub commented 4 weeks ago

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 commented 4 weeks ago

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 commented 4 weeks ago

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 commented 3 weeks ago

Is solved. Thank you very much for help @Ajmal0197

diessetechnology commented 3 weeks ago

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 commented 3 weeks ago

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 commented 2 weeks ago

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.