Developer setup
Android Studio
Use Android Studio 4.2+.
Kotlin style
If you would like Android Studio to help format your code, follow these steps to set up your Android Studio:
- Install and configure the ktfmt plugin in Android Studio by following these steps:
- Go to Android Studio's
Settings
(orPreferences
), select thePlugins
category, click theMarketplace
tab, search for thektfmt
plugin, and click theInstall
button - In Android Studio's
Settings
(orPreferences
), go toEditor
→ktfmt Settings
, tickEnable ktfmt
, change theCode style
toGoogle (Internal)
, and clickOK
- Go to Android Studio's
- Indent 2 spaces. In Android Studio's
Settings
(orPreferences
), go toEditor
→Code Style
→Kotlin
→Tabs and Indents
, setTab size
,Indent
andContinuation indent
to2
, and clickOK
. - Use single name import sorted lexicographically. In Android Studio's
Settings
(orPreferences
), go toEditor
→Code Style
→Kotlin
→Imports
, inTop-level Symbols
andJava statics and Enum Members
sections selectUse single name import
option, remove all the rules inPackages to Use Imports with '*'
andImport Layout
sections and clickOK
.
Now you can go to Code
→ Reformat code
, or press Ctrl+Alt+L
(⌘+⌥+L
for Mac) to automatically format code in Android Studio.
Note that you don't have to do any of these. You could rely on spotless to format any code you want to push. For details see below.