Given the following imports
import javax.inject.Inject
import kotlinx.android.synthetic.main.fragment.*
Android Studio rearrange to the following when pressing control + option + o
import kotlinx.android.synthetic.main.fragment.*
import javax.inject.Inject
Which is not in lexicographic order. My pre-commit
hook running ktlint
then fails because of this. Is there any way to fix this issue?
The latest IntelliJ IDEA / Android Studio might not be able to conform to full specifications in the Android Kotlin style guide. So, currently, there is no straight-forward way of arranging the imports lexicographic order in IntelliJ IDEA / Android Studio.
For now, you may want to disable this check for Klint by disabling 'import ordering' in the .editorconfig file in the root of your project:
[*.{kt,kts}]
disabled_rules = import-ordering
This will disable the check in your project.
IntelliJ IDEA / Android Studio doesn't let you order imports alphabetically, neither in Java nor in Kotlin.
However Java features an Import layout section, which can give you some control. But still it's impossible to have an exact ordering, as you want it.
This isn't available for Kotlin is now available in Kotlin too. You can look at https://youtrack.jetbrains.com/issue/KT-10974
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With