'How to prevent Androidstudio from automatically replacing Charset.forName("UTF-8") with StandardCharsets.UTF_8 when commiting to git?

I am implementing java 1.8 code that should be compatible with android-api 14 (i am using minSdk 14 and targetSdk 31)

    // StandardCharsets.UTF_8=Charset.forName("UTF-8") not supported by api-14
    Charset utf8 = Charset.forName("UTF-8"); // StandardCharsets.UTF_8;
    try (JsonReader reader = new JsonReader(new InputStreamReader(jsonInputStream, utf8))) {...}

After commiting to git the code becomes

    // StandardCharsets.UTF_8=Charset.forName("UTF-8") not supported by api-14
    Charset utf8 = StandardCharsets.UTF_8; // StandardCharsets.UTF_8;
    try (JsonReader reader = new JsonReader(new InputStreamReader(jsonInputStream, utf8))) {...}

Android studio git-commit replaced Charset.forName("UTF-8") with StandardCharsets.UTF_8 which requires api-19 and is not compatible with api-14.

Is there a way to tell Android-Studio not to replace the code? Somthing like a toggle option //DISABLE-OPTIMISATON ?

--

I am using Android Studio bumblebee 2021.1.1 Patch 1

Git commit options:

  • [X] Reformat code
  • [X] Rearrange code
  • [X] optimize imports
  • [X] cleanup

With these setting the code is not replaced

  • [_] Reformat code
  • [X] Rearrange code
  • [X] optimize imports
  • [_] cleanup


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source