How do I disable Wildcard imports for all Kotlin files in Android Studio?

Viewed 7067

The Android Kotlin Style Guide says:

Wildcard imports (of any type) are not allowed.

How do I configure Android Studio to do this automatically?

1 Answers

You can set your Android Studio preferences to remove all wildcard imports from Kotlin files.

  1. Open Android Studio Preferences: Editor > Code Style > Kotlin
  2. Select Use single name import for Top-level Symbols
  3. Select Use single name import for Java Statics and Enum Members
  4. Remove all packages from Packages to Use Import with by clicking the minus - symbol until it says Nothing to show

For each Kotlin file, you can fix imports with Code > Optimize Imports (shortcut ⌃⌥O on Mac).

Screenshot of Android Studio 4.1.2 Settings: No Kotlin Wildcard Imports

Related