DEV Community

Ajmal Hasan
Ajmal Hasan

Posted on

compileDebugJavaWithJavac because error: switch expressions are not supported in -source 11: Solution

I recently encountered an issue in ReactExoplayerView where android build was crashing with mentioned error. Here's the fix that resolved the problem:

Original Code (Using a Switch Expression):

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

Updated Code (Using a Traditional Switch Statement):

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;
}
Enter fullscreen mode Exit fullscreen mode

The issue was caused by the switch expression, which I replaced with a traditional switch statement. After making this change, the playback speeds worked correctly.

Final Step:

After making the code change, I used patch-package to ensure the fix was preserved:

npx patch-package react-native-video
Enter fullscreen mode Exit fullscreen mode

This fixed the bug and ensured smooth playback speed transitions in my React Native app.

Top comments (0)