How to disable the Android Studio code style warning "... can be simplified ..."

I use productFlavorsand buildConfigFieldto enable / disable functions in the application for Android:

productFlavors {
    vanilla {
        buildConfigField "boolean", "FEATURE_SAR", "false"
    }
    edge {
        applicationIdSuffix ".edge"
        buildConfigField "boolean", "FEATURE_SAR", "true"
    }
}

Could not find a way to disable the Android Studio code style warning: BuildConfig.FEATURE_SAR can be simplified to false.

As you can see in my code, I tried many ways, but none of them work. And I can not find the settings where I can disable this in Android Studio.

@Override
@SuppressWarnings("SimplifiableIfStatement") // no effect
@SuppressLint("SimplifiableIfStatement")     // no effect
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Set<Integer> suppressPositions = new HashSet<>();

    //noinspection SimplifiableIfStatement <-- no effect
    if (!BuildConfig.FEATURE_SAR) {
        suppressPositions.add(IDX_SAR);
    }

    SimpleAdapter adapter = ViewUtils.createSimpleAdapter(
        getContext(), MENU_RESOURCES, suppressPositions);
    setListAdapter(adapter);
}

Of course, there are ways to get around this using resources, but for some reason I cannot use resources in all cases. Therefore, the question is only how to disable these warnings, and not how best to manage the configuration in Android / Gradle.

+5
2

, , ALT + ENTER. . " ", X, :

Example

+5

.

, , IDE , :

buildConfigField("boolean", "FEATURE_STAR", "Boolean.parseBoolean(\"true\")")

BuildConfig :

public static final boolean FEATURE_STAR = Boolean.parseBoolean("true");

: , BuildConfig.DEBUG.

+1

Source: https://habr.com/ru/post/1623536/


All Articles