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.

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay