13

When I change small thing in XML layout files like maxLength of a TextInputEditText I need to clean project to let AS pickup change.

Structure of res folders is:

res
- layout
- drawables
- ...

No more subfolders. AS 3.1.1, Gradle 4.6. I tried to add this in gradle:

sourceSets {
    main.res.srcDirs =  [
                         'src/main/res/anim',
                         'src/main/res/color',
                         'src/main/res/drawable',
                         'src/main/res/drawable-hdpi',
                         'src/main/res/drawable-mdpi',
                         'src/main/res/drawable-xhdpi',
                         'src/main/res/drawable-xxhdpi',
                         'src/main/res/drawable-xxxhdpi',
                         'src/main/res/menu',
                         'src/main/res/mipmap-dpi',
                         'src/main/res/mipmap-hdpi',
                         'src/main/res/mipmap-mdpi',
                         'src/main/res/mipmap-xhdpi',
                         'src/main/res/mipmap-xxhdpi',
                         'src/main/res/mipmap-xxxhdpi',
                         'src/main/res/raw',
                         'src/main/res/values',
                         'src/main/res/values-land',
                         'src/main/res/values-large',
                         'src/main/res/values-v21',
                         'src/main/res/valuesw820dp',
                         'src/main/res/xml',
                         'src/main/res/layout',
                         'src/main/res']
}

enter image description here

Is there a way to prevent cleaning the project every time for change to take effect?

So whenever I make a change to the XML files and run the app, I should see my change but I have to clean the project every time and its getting annoying.

Tomasz Kryński
  • 513
  • 4
  • 23

6 Answers6

6

First of all you need to create your additional resource folder beside res folder instead of creating inside it. Then try make XML like this example:

sourceSets{
     main  {
         manifest.srcFile 'src/main/AndroidManifest.xml'
         java.srcDirs = ['src/main/java', '.apt_generated']
         aidl.srcDirs = ['src/main/aidl', '.apt_generated']
         res.srcDirs = [
            'src/main/res',
            'src/main/test',
            'src/main/login',
            'src/main/main',
            'src/main/includes'
        ]
    }
}

Note: Your additional resource folder will change effect without cleaning the project.

  • In other projects it works when i have layout under res folder, so I expect same. – Tomasz Kryński Jun 13 '18 at 18:14
  • you can create new project or modify existing one. –  Jun 13 '18 at 18:15
  • Of course I can, I want gradle to pick up my changes done in default android project folder `res/layout`. It is not doing it and you tell me I need to move `layout` out of `res` folder in order to make it work, so I told you that it works as `res/layout` on dummy project it should here without breaking default folder structure. – Tomasz Kryński Jun 13 '18 at 19:19
  • it's doesn't work in Android studio 3.2 also in project structure, how can i solve the problem ? – Prince Dholakiya Oct 09 '18 at 06:32
3

Problem was with build flavors. One of them was named main and that causes problems with projects scanning. Changing name fixed issue. It is marked in newer versions of gradle plugin.

Tomasz Kryński
  • 513
  • 4
  • 23
1

I dont think you need to clean the project everytime. For some minor changes you dont even need to run the app again, simply clicking on instant run will do, as it will hotswap the changes directly into the current activity.

Also is there any particular reason you are adding the paths to gradle? AFAIK, you need to do this only when you change the paths and set it to something else. In your case the paths are at their default locations so I dont see the reasoning behind this. Try removing this from the gradle and switching on instant run.

These links should help:

https://developer.android.com/studio/run/#instant-run https://developer.android.com/studio/write/add-resources

shiredude95
  • 560
  • 3
  • 7
  • Problem is, lets say, I change maxLength of TextInputEditText, hit 'run' and expect to get this changed on phone but it isn't. I need to clean project and run app. – Tomasz Kryński Jun 07 '18 at 14:57
  • have you tried removing the default path directories from the gradle file? Try and see if the issue is resolved, if it still exists you could test the following as troubleshooting measures to narrow down your cause of trouble: 1)Make a new dummy project and see if instant run works in that project without clean/building. If it does not then likely there is some errror with your AS build or your system. If it does work there however then we can be certain the issue is with this particular project. – shiredude95 Jun 07 '18 at 16:01
  • I just tried default path directories in gradle as one of the solutions, it didn't work. I have removed them since. Dummy project works fine, no rebuilding nor cleaning to get changes in layout. – Tomasz Kryński Jun 07 '18 at 18:25
  • Ok,so this would mean the issue is with this particular project. Have you tried a bare bones module and implement the same operation in a dummy activity in it. If there are no issues the this is a module based problem rather than a project based, but if the issue still exists then we can be sure this is a project based issue. – shiredude95 Jun 07 '18 at 19:02
  • I have problem with changing any layout/resource in project, it just not pick up changes. Any change in .xml is picked up after rebuild or clean, it could be removal of text field, just one property or string. I dont know what do you mean by 'bare bones module'. – Tomasz Kryński Jun 07 '18 at 20:49
  • Have you selected GradleAwareMake in the Run Configurations. There was a recent bug in AS that led to this issue. This post talks about it https://stackoverflow.com/questions/49701214/android-studio-3-1-rebuild-project-each-time-to-see-the-changes – shiredude95 Jun 07 '18 at 20:52
  • I have GradleAwareMake, also updated AS and this do not fixed issue. – Tomasz Kryński Jun 07 '18 at 21:55
0

There is no need to clean every time after changing in xml layout file , you just need to refresh your layout by clicking on blue icon at right end side of your preview section as shown in below image . in that there is property named Force Refresh Layout. click on that and your layout will be refreshed.enter image description here

ANAL SHAH
  • 51
  • 4
0

You can try enabling the INTANT RUN feature in Android Studio. It worked for me.

If you are using MAC go to Preferences, Search for Instant Run and check the Enable option on right side window.

After enabling, instead of running you can Go to RUN and click on Apply Changes.

AMT
  • 136
  • 5
0

Upgrade Android Studio to 3.1.3 solve my problem

Download Latest Version 3.1.3

or what you can do is click this info button and then Refresh the layout will solve the problem

enter image description here

Tabish Hussain
  • 852
  • 5
  • 13
  • I have 3.1.3. This button you highlighted shows new window with 'no issues'. Forcing to reload then running app again or do instant run did not pick up changes to layout(i tried removing image from loading screen, if it matter). – Tomasz Kryński Jun 13 '18 at 19:14