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")
@SuppressLint("SimplifiableIfStatement")
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Set<Integer> suppressPositions = new HashSet<>();
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.