How to control when Imports are replaced by wildcard in Android Studio in Kotlin files

Viewed 4009

I noticed that for up to 4 imports from the same package, auto-import will simply append the import in the list:

import android.support.v7.widget.AppCompatImageButton
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.support.v7.widget.Toolbar

But adding a 5th import will make auto-import switch to a wildcard:

import android.support.v7.widget.*

Is there a way to keep auto-import on but tell it to not do that, or change the threshold? I don't mind having a long list of imports, it feels... familiar.

2 Answers

You can set this under the Kotlin "Code Style" section in Preferences:

Imports

The Android Kotlin Style Guide says:

Wildcard imports (of any type) are not allowed.

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

Screenshot of Android Studio 4.1.2 Settings: No Kotlin Wildcard Imports

Related