How can I configure Android studio to add new line at end of file?

sujithvm picture sujithvm · Jun 7, 2014 · Viewed 11.8k times · Source

I use Android Studio and when I commit to a repo on GitHub and view git diff I see a red marker at end of line for few files with a warning 'No newline at end of file'. How can I configure Android Studio to ensure that it does add a newline at file of file for every file. Thank you.

Answer

Mark Bowker picture Mark Bowker · Feb 22, 2015

Yes, you can configure Android Studio to automatically add a new line at the end of a file.

File | Settings... menu, then Editor under IDE Settings, then check the Ensure line feed at file end on Save option box.

This will only take effect on freshly edited files after the setting has been enabled.


UPDATE

On newer versions of Android Studio, the preference location has changed to

File > Preferences > Editor > General > Ensure line feed at file end on Save