Member-only story

Android Studio tip — Exclude unwanted imports

Matthew Dolan
2 min readSep 10, 2021

--

Photo by Todd Kent on Unsplash

The auto-import functionality of Android Studio is often cluttered, presenting the user with imports for deprecated classes. For example, even though junit.framework.Assert is deprecated, the IDE still provides it as a choice when auto-importing and auto-completing on assertEquals:

Auto-import on assertEquals showing deprecated junit.framework.Assert
Auto-complete on assertEquals showing deprecated junit.framework.Assert.assertEquals

Fortunately, there’s something simple you can do to exclude certain imports.

With auto-import, navigate with the right-arrow key to display exclusion options:

Press right-arrow to show exclusion options from auto-import

With auto-complete, press Option ⌥ + Return on a Mac to display the same exclusion options:

Press Option ⌥ + Return to show exclusion options from auto-complete

Selecting any of the items in these exclusion menus presents the below dialog with your chosen…

--

--

Matthew Dolan
Matthew Dolan

Written by Matthew Dolan

Matt Dolan has been eating doughnuts and developing with Android since the dark days of v1.6.

No responses yet