178

I've just updated to Android Studio 3.5 and now when I try to refactor the file AndroidManifest.xml, all my app permissions are moved to the bottom of the file.

Has anyone else faced this issue? Is there any solution for this?

Before refactor:

enter image description here

After refactor:

enter image description here

It is applicable to my all project files.

Why it matters:

enter image description here

medavox
  • 175
  • 2
  • 11
Sagar Kacha
  • 8,338
  • 4
  • 18
  • 27
  • 4
    why is this a problem that requires a solution? – Tim Aug 21 '19 at 12:04
  • 13
    @TimCastelijns: If nothing else, it introduces unexpected noise in version control. I can't rule out real problems in old Android devices, as `` used to need to appear before ``, though it is possible that was really an old tooling problem that we would not see nowadays. – CommonsWare Aug 21 '19 at 12:09
  • 8
    FWIW, [I wrote up more about the problem](https://commonsware.com/blog/2019/08/21/android-studio-3p5-xml-reformatting-problems.html), including filing [a dedicated issue for the 3.4 -> 3.5 upgrade problem](https://issuetracker.google.com/issues/139793887) that triggers this effect. – CommonsWare Aug 21 '19 at 15:26
  • 9
    @TimCastelijns in a xml layout, it changes the order of you components (ex : my ImageView came before my TextView, and that's not what I want !) – rcperso Aug 24 '19 at 14:24
  • 4
    They just undid all of their efforts towards stability with 3.5 with this. Probably the worst AS bug ever since it can silently break your app at run time :/ – Carson Holzheimer Sep 02 '19 at 03:19
  • ridiculous bug! – Williaan Lopes Sep 21 '19 at 02:36

9 Answers9

268

You just need to set xml layout for Android applications from the settings.

Follow this steps:

1. Go to Android Studio > Preferences. For Windows, go to File > Settings.

enter image description here

2. Search for xml in search bar.

enter image description here

3. Under code style section, select xml tab.

enter image description here

4. In the top right corner, click on set from... and under predefined style, select Android

enter image description here

5. Click on Apply and try to refactor.

pRaNaY
  • 24,642
  • 24
  • 96
  • 146
Birju Vachhani
  • 6,072
  • 4
  • 21
  • 43
  • 8
    After this you may need to restart Android Studio. – tasomaniac Aug 24 '19 at 15:49
  • This got me most the way there but I think the issue is the lack of "attribute" property tag's in the arrangement tab. See the screenshot in my own answer for details. – Slartibartfast Aug 27 '19 at 06:19
  • From what I can tell the reason this suggestion works is because it inserts these "attribute" type tags, though it does so at the cost of resetting any other customisations you may have set so you'll have to re-implement those again after, but it work's :). – Slartibartfast Aug 28 '19 at 00:46
  • 1
    I am afraid that this solution is not working in my case. – P Vartak Sep 07 '19 at 04:49
  • 2
    On Android Studio 4.0.1, this bug still exists. It changes the order of my components in xml layout when reformatting. So ridiculous! – hanswim Aug 06 '20 at 08:01
17

Reset the appropriate Android code style as follows.

For Windows Only

Step1: Click on the file menu.

Step2: Navigate to Setting.

Step3: Find Editor in the Left Panel**.

Step4: Find Code Style in the Sub Menu of Editor.

Step5: Click on XML in the Sub Menu of Code Style.

Step6: Click on Set from in Top right corner of Right panel.

Step7: Select Predefined Style.

Step8: Select Android.

Step9: Click OK.

For macOS Only

Step1: Click on the Android Studio menu.

Step2: Navigate to Preferences.

Step3: Find Editor in the Left Panel**.

Step4: Find Code Style in the Sub Menu of Editor.

Step5: Click on XML in the Sub Menu of Code Style.

Step6: Click on Set from in Top right corner of Right panel.

Step7: Select Predefined Style.

Step8: Select Android.

Step9: Click OK.

VIISHRUT MAVANII
  • 11,410
  • 7
  • 34
  • 49
10

It seems the default scheme leaves out the "attribute" property in the arrangement rules. Adding them back in works like a charm for me.

The correction can be made in: Preferences > Editor > Code Style > XML enter image description here

Slartibartfast
  • 591
  • 5
  • 18
5

Just adding more details .

This is a known issue with android studio from Android Studio 3.5 Canary 8 . It should get fixed in next version as this turned out to affect large number of developers .

You can see status of the bug here

Also the solution is

Broken XML code style

When editing XML code, the IDE might apply an incorrect code style when you select Code > Reformat Code from the menu bar. To fix this issue, reset the appropriate Android code style as follows:

  1. Open the Settings window by clicking File > Settings (on macOS, Android Studio > Preferences).
  2. In the left panel, click Editor > Code Style > XML.
  3. Near the top-right corner of the right panel, select Set from > Predefined Style > Android
  4. Click OK.

Which is found here -> Known issues with Android Studio and Android Gradle Plugin

Edit: This is now fixed in Android studio version 3.5.2

Manohar
  • 22,116
  • 9
  • 108
  • 144
3
  • ctrl + alt + s
  • Search XML

I wanted to do the same steps as the first answer, but I just needed to change the default scheme to project.

I hope that you also solve it this way . Sorry for my English !

enter image description here

enter image description here

Irvin Joao
  • 1,010
  • 8
  • 8
1

If you have a custom code style defined, you have to specify a type for each rule: tag or attribute.

It seems like after the update, if you do not specify a type, the rules will be applied to both. Not sure if it is a bug, but that's how i fixed.

This does not work on 3.5

After adding the attribute type to each rule, it worked

Kine
  • 41
  • 4
1

Please follow these steps for Windows version of "Android Studio 3.5"

1: Click on the File in the Menu.

2: Go to Settings.

enter image description here.

3: Click on Editor.

4: Click on Code Style

5: Click on XML.

enter image description here

6: Click on "Set from..." in top-right corner.

7: Select Predefined Style.

8: Select Android.

enter image description here

9: Click OK.

Md. Rejaul Karim
  • 694
  • 7
  • 14
1

3.5.0 known issue

When editing XML code, the IDE might apply an incorrect code style when you select Code > Reformat Code from the menu bar. To fix this issue, reset the appropriate Android code style as follows:

  • Open the Settings window by clicking File > Settings (on macOS, Android Studio > Preferences).
  • In the left panel, click Editor > Code Style > XML.
  • Near the top-right corner of the right panel, select Set from > Predefined Style > Android.
  • Click OK.
Ahamadullah Saikat
  • 4,437
  • 42
  • 39
1

For anyone searching this for Android Studio 4+ :

File -> Setting -> Editor -> Code Style -> XML -> Arrangement ->
  • Set Force rearrange to "Never"
  • Set from to "Android"
Muhammad Zahab
  • 1,049
  • 10
  • 21