The fix on the issue I've posted here https://github.com/pinterest/ktlint/issues/685 indeed fixed a lot of inconsistencies between formatting via ktlint and AndroidStudio, however, I found another bug.
This is the code before formatting, (ktlint sees no issues)

After formatting via Android Studio

ktlint version 0.37.2
Found another bug, Idk if, that's the same cause. Should I create separate PR for that?
Before:

After:

Hello,
I have the same issue here, the indents of the if () and the function call are stacking together with Android Studio formatting which I think is normal but ktlint wants only one indent:
Android Studio formatting:

ktlint formatting:

Not sure if I should be dropping this here or in a separate issue, imports ordering is also off:
Android Studio
import android.os.Bundle
import android.view.View
import com.honestbank.android.apply.presentation.R
import com.honestbank.android.apply.presentation.common.setFieldListener
import com.honestbank.android.common.presentation.di.ViewModelProvidersWrapper
import com.honestbank.android.common.presentation.livedata.nonNull
import com.honestbank.android.common.presentation.livedata.observe
import com.honestbank.android.common.presentation.view.BaseFragment
import com.honestbank.android.common.presentation.view.updateView
import kotlinx.android.synthetic.main.fragment_apply_email_layout.emailNavigateButton
import kotlinx.android.synthetic.main.fragment_apply_email_layout.emailPassword
import kotlinx.android.synthetic.main.fragment_apply_email_layout.emailText
import kotlinx.android.synthetic.main.fragment_apply_email_layout.load_indicator
import javax.inject.Inject
vs
ktlint 0.37.0
import android.os.Bundle
import android.view.View
import com.honestbank.android.apply.presentation.R
import com.honestbank.android.apply.presentation.common.setFieldListener
import com.honestbank.android.common.presentation.di.ViewModelProvidersWrapper
import com.honestbank.android.common.presentation.livedata.nonNull
import com.honestbank.android.common.presentation.livedata.observe
import com.honestbank.android.common.presentation.view.BaseFragment
import com.honestbank.android.common.presentation.view.updateView
import javax.inject.Inject
import kotlinx.android.synthetic.main.fragment_apply_email_layout.emailNavigateButton
import kotlinx.android.synthetic.main.fragment_apply_email_layout.emailPassword
import kotlinx.android.synthetic.main.fragment_apply_email_layout.emailText
import kotlinx.android.synthetic.main.fragment_apply_email_layout.load_indicator
@jai are you running ktlint with --android option? If so, then it's expected behavior, as per android styleguide the imports should be sorted alphabetically
thanks @romtsn so for happy coexistence between ktlint and Android Studio I'm going to have to disable the android option it seems?
Either that or you could add kotlin_imports_layout=idea to your .editorconfig as mentioned here, and they will happily coexist even with --android option :)
@romtsn so I created a .editorconfig file in the project root with the following contents:
[*.{kt,kts}]
kotlin_imports_layout=idea
Running ktlint ended up throwing a bunch of errors:
/android-app/app/src/test/kotlin/com/honestbank/android/model/CampaignTest.kt:0:0: Internal Error (import-ordering). Please create a ticket at https://github.com/pinterest/ktlint/issues (if possible, provide the source code that triggered an error) (cannot be auto-corrected)
I'll try and dig deeper to see what's going on. This is ktlint running via a Gradle plugin so will try the command line ktlint and see if that makes a difference.
This might be a bug (also please try to use 0.37.2 as there were some fixes for the import-ordering rule). If this still isn't working, feel free to open a new issue with code sample
Looks like still having issues even with 0.37.2. Opened https://github.com/pinterest/ktlint/issues/826
@PPetka the first issue is fixed by #833 but the second one is unfortunately not that easy to fix - please track it in #816