我正在使用productFlavors和buildConfigField在我的Android应用程序中启用/禁用功能:
productFlavors { vanilla { buildConfigField "boolean", "FEATURE_SAR", "false" } edge { applicationIdSuffix ".edge" buildConfigField "boolean", "FEATURE_SAR", "true" } }还没有找到一种方法来禁用Android Studio代码样式警告,说''!BuildConfig.FEATURE_SAR'可以简化为'false'“。
正如你在我的代码中看到的,我尝试了很多方法,但都没有成功。 我找不到可以在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); }当然,有些方法可以通过使用资源来解决这个问题,但由于某些原因,我无法在所有情况下使用资源。 所以问题只是如何禁用这些警告,而不是如何更好地处理Android / Gradle中的配置管理。
I'm using productFlavors and buildConfigField to enable/disable features in my Android app:
productFlavors { vanilla { buildConfigField "boolean", "FEATURE_SAR", "false" } edge { applicationIdSuffix ".edge" buildConfigField "boolean", "FEATURE_SAR", "true" } }Haven't found a way to disable Android Studio code style warning saying "'!BuildConfig.FEATURE_SAR' can be simplified to 'false'".
As you can see in my code, I've tried many ways but none of them works. And I cannot find the setting 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 by using resources, but for some reasons I cannot use resources in all cases. So the question is only how to disable these warnings, not how to better handle config management in Android/Gradle.
最满意答案
一般情况下,一旦将光标放入警告中,请按ALT + ENTER。 然后放大警告的上下文菜单。 应该有一个条目“禁用检查”显示一个红色的X,如下所示:
In general once you put the cursor into the warning press ALT + ENTER. Then enlarge the context-menu of your warning. There should be a entry "Disable Inspection" displayed with a red X as shown here:
更多推荐
发布评论