Currently when I want to format my code, I run this in the terminal in my android studio directory
https://github.com/pinterest/ktlint
./gradlew ktlint