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

error: switch rules are not supported in -source 11 #2551

Closed
Hugo-Tek opened this issue Nov 27, 2024 · 10 comments
Closed

error: switch rules are not supported in -source 11 #2551

Hugo-Tek opened this issue Nov 27, 2024 · 10 comments
Labels
Missing repro This issue need minimum repro scenario

Comments

@Hugo-Tek
Copy link

Hugo-Tek commented Nov 27, 2024

Description

Hi, I have a problem that I don't understand how to solve, can you help me?

I upgraded my react-native-svg version from ‘^15.4.0’ to ‘15.9.0’.

yet my FeBlendView.java file is different than the one in the repo (on Github) :

package com.horcrux.svg;

import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import com.facebook.react.bridge.ReactContext;
import java.util.HashMap;

@SuppressLint("ViewConstructor")
class FeBlendView extends FilterPrimitiveView {
  String mIn1;
  String mIn2;
  FilterProperties.FeBlendMode mMode;

  public FeBlendView(ReactContext reactContext) {
    super(reactContext);
    super.mFilterSubregion.mX = new SVGLength(0);
    super.mFilterSubregion.mY = new SVGLength(0);
    super.mFilterSubregion.mW = new SVGLength("100%");
    super.mFilterSubregion.mH = new SVGLength("100%");
  }

  public void setIn1(String in1) {
    this.mIn1 = in1;
    invalidate();
  }

  public void setIn2(String in2) {
    this.mIn2 = in2;
    invalidate();
  }

  public void setMode(String mode) {
    this.mMode = FilterProperties.FeBlendMode.getEnum(mode);
    invalidate();
  }

  @Override
  public Bitmap applyFilter(HashMap<String, Bitmap> resultsMap, Bitmap prevResult) {
    Bitmap in1 = getSource(resultsMap, prevResult, this.mIn1);
    Bitmap in2 = getSource(resultsMap, prevResult, this.mIn2);

    if (this.mMode == FilterProperties.FeBlendMode.MULTIPLY) {
      CustomFilterFunction multiply =
          (src, dst) -> {
            float[] res = new float[4];
            res[0] = 1f - (1f - src[0]) * (1f - dst[0]);
            res[1] =
                src[1] * src[0] * (1f - dst[0])
                    + dst[1] * dst[0] * (1f - src[0])
                    + src[1] * src[0] * dst[1] * dst[0];
            res[2] =
                src[2] * src[0] * (1f - dst[0])
                    + dst[2] * dst[0] * (1f - src[0])
                    + src[2] * src[0] * dst[2] * dst[0];
            res[3] =
                src[3] * src[0] * (1f - dst[0])
                    + dst[3] * dst[0] * (1f - src[0])
                    + src[3] * src[0] * dst[3] * dst[0];
            return res;
          };
      return CustomFilter.apply(in1, in2, multiply);
    }

    Bitmap result = Bitmap.createBitmap(in1.getWidth(), in1.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    canvas.drawBitmap(in1, 0, 0, paint);

    switch (this.mMode) {
      case NORMAL -> {
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OVER));
      }
      case SCREEN -> {
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN));
      }
      case LIGHTEN -> {
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.LIGHTEN));
      }
      case DARKEN -> {
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DARKEN));
      }
      case MULTIPLY -> {}
    }
    canvas.drawBitmap(in2, 0, 0, paint);

    return result;
  }
}

Steps to reproduce

When I tried to build, this error appear :

> Task :react-native-svg:compileDebugJavaWithJavac FAILED
/Users/usr/Documents/Projects/prj/node_modules/react-native-svg/android/src/main/java/com/horcrux/svg/FeBlendView.java:74: error: switch rules are not supported in -source 11
      case NORMAL -> {
                  ^
  (use -source 14 or higher to enable switch rules)
/Users/usr/Documents/Projects/prj/node_modules/react-native-svg/android/src/main/java/com/horcrux/svg/FeCompositeView.java:71: error: switch rules are not supported in -source 11
      case OVER -> {
                ^
  (use -source 14 or higher to enable switch rules)

Snack or a link to a repository

don't have

SVG version

15.9.0

React Native version

0.72.3

Platforms

Android

JavaScript runtime

None

Workflow

React Native

Architecture

None

Build type

None

Device

None

Device model

No response

Acknowledgements

Yes

@github-actions github-actions bot added the Missing repro This issue need minimum repro scenario label Nov 27, 2024
Copy link

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

@jakex7
Copy link
Member

jakex7 commented Nov 28, 2024

Hey @Hugo-Tek,
These changes have not been published yet and will land in the next release, likely at the beginning of next week.

@ngioldasis
Copy link

I have the same problem. Did anyone manage to solve it?

@jakex7
Copy link
Member

jakex7 commented Dec 3, 2024

Hi @Hugo-Tek, @ngioldasis,
The fix has been released in https://github.com/software-mansion/react-native-svg/releases/tag/v15.10.0, so you should now be able to update to the latest version.

@jakex7 jakex7 closed this as completed Dec 3, 2024
@prabhat999
Copy link

Hello @jakex7
Fixes made in the v15.10.0 does not resolves the above mentioned error. I am still getting the same error.

@Hugo-Tek @ngioldasis This solves the error ->
"react-native-svg": "15.0.0",
"react-native": "0.72.1",

@ngioldasis
Copy link

Still getting this error in react 0.72.7.

@DevNomadAbhi
Copy link

You need to update your project's java version. try using with java 17.
if you have compile options inside app level => build gradle then update the java version there or just search JavaVersion.VERSION_{your project's java version} and change it with JavaVersion.VERSION_17.

** This is only a workaround which I did just now , IDK what it will break in the project as of now. But its working for me in current scenario.

@ignaciotcrespo
Copy link

I fixed it using "react-native-svg": "^15.10.1" and adding support for java 14 in the svg gradle file. Here is a patch to apply using yarn patch-package

react-native-svg+15.10.1.patch

@choijiho0021
Copy link

yes i have same error

@zeilsell-user1
Copy link

Is this going to be fixed at some point?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Missing repro This issue need minimum repro scenario
Projects
None yet
Development

No branches or pull requests

8 participants