Varun Bhatia
Varun Bhatia

Reputation: 4396

Report unused imports as error in Android Studio or IntelliJ

Is there any way/setting in Android Studio to report the unused imports in java files as error?

In Eclipse, lint reported this as error pretty easily.

Upvotes: 3

Views: 1987

Answers (4)

CanCoder
CanCoder

Reputation: 1150

For Android Studio Arctic Fox | 2020.3.1 Patch 4, follow this Android Studio -> Preferences -> Editor -> General -> Auto Import

enter image description here

Upvotes: 1

abdullahicyc
abdullahicyc

Reputation: 89

First remove references of these imports from the code.
Then you can use this shortcut ALT + CTRL + O

Upvotes: 1

nana futoi
nana futoi

Reputation: 76

Applies to Android Studio and IntelliJ

You could go to File/Settings then browse to Editor/Inspections/Import.

Change Severity of Unused Import to Error

enter image description here

Upvotes: 6

Dhaval Parmar
Dhaval Parmar

Reputation: 18978

try this.


its automatically remove unused imports

yourProject --> Right Click --> Optimize Imports


lint : its also show unused imports in java files as error

yourProject --> Right Click --> Analize --> Inspect Code

Upvotes: 1

Related Questions