Remove "method Is Never Used" Warning For Onclick Annotation In Android Studio
Solution 1:
The correct way in Android Studio to suppress these warnings is to press Alt+Enter on the method giving the Method 'yourFunction()' is never used warning, and selecting
Suppress for methods annotated by'butterknife.OnClick'
Solution 2:
Simply add this annotation:
@SuppressWarnings("unused")
Just like that:
@SuppressWarnings("unused")
@OnClick(R.id.myButton)
public void clickHandler()
{
// ...
}
My personal preference (which I see as good practice) is to add a comment with a brief explanation:
@SuppressWarnings("unused")// it's actually used, just injected by Butter Knife
Solution 3:
Osvald's answer is spot on.
However, if you want to avoid suppressing warnings separately for each type of butterknife annotation, follow his instructions, and then open up .idea/misc.xml
and find this section:
<componentname="EntryPointsManager"><entry_pointsversion="2.0" /><listsize="1"><itemindex="0"class="java.lang.String"itemvalue="butterknife.OnClick" /></list></component>
Therein, simply replace butterknife.OnClick
with butterknife.*
.
From now on, all your injected event handlers will evade the warning.
Solution 4:
Add another dependency for the compiler:
Gradle
dependencies {
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'// new line
compile 'com.jakewharton:butterknife:8.4.0'// original library
}
This is recommended on the official website.
Remember to Build -> Rebuild Project, so it will generate usages and make the warning go away.
Post a Comment for "Remove "method Is Never Used" Warning For Onclick Annotation In Android Studio"