Android Studio 3.5 Upgrade XML Reformatting Problems

If you upgrade Android Studio 3.4 to 3.5, you may run into a problem where reformatting an XML file (e.g., via Ctrl-Alt-L) reorders the XML elements in each level of the hierarchy. So, for example, you might have a <uses-permission> before <application> in your <manifest> element; reformatting would flip the order of those elements. It seems to be alphabetizing them.

For the manifest, this might almost be survivable. However, lots of things in Android are dependent upon XML element order, such as the children of a LinearLayout, the children of <menu>, the children of <layer-list>, and so on.

The original issue for this appears to be this one. It is marked as “fixed”, though that appears to be overly optimistic. A number of developers are running into the problem, filing other issues and asking Stack Overflow questions. I ran into it myself in my “daily driver” Android Studio setup.

Based on some experiments, the problem seems to be limited to upgraders. I cannot reproduce the effect with a fresh Android Studio 3.5 installation.

The simple fix is outlined in the aforementioned Stack Overflow question:

  • Go into the Settings screen (File > Settings, or Apple > Settings, depending on your OS)

  • Navigate into Editor > Code Style > XML

  • In the upper-right of that dialog, choose Set From > Predefined Style > Android

The real problem lies in the “Arrangement” tab in that XML code style screen. After an upgrade from 3.4 to 3.5, you wind up with arrangement rules like these:

Broken Android Studio 3.5 XML Arrangement Rules

There may be a more surgical fix that can be applied to those rules, editing each of them to limit them to attributes, but I have not tried this. Applying the Android predefined style replaces the buggy post-upgrade rules with valid rules:

Repaired Android Studio 3.5 XML Arrangement Rules

Because the problem lies with an upgrade, it might be tricky for Google to fix it with yet another upgrade to some future 3.5.1 version. With luck, they’ll find a solution.

Regardless, when you upgrade to Android Studio 3.5 from 3.4, double-check these arrangement rules and fix them if they appear broken.

Many thanks to Birju Vachhani for his writeup of the steps to fix the problem!


Need an extra hand with your Android app development project? CommonsWare can help — reach out for details!