Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to clean project after changing layouts in Android Studio

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.

like image 249
Tomasz Kryński Avatar asked Jun 04 '18 20:06

Tomasz Kryński


People also ask

How do I clean my Android project?

Clear your project directory Obviously, try to clean your project from android studio : “Build -> Clean Project”. This will clear your build folders. Clear the cache of Android Studio using “File -> Invalidate Caches / Restart” choose “Invalidate and restart option” and close Android Studio.

What happens when you clean a project in Android Studio?

Cleaning an Android project simply deletes the build directory. It removes the . class files that are generated when you compile your project and then recompiles again.

Is it safe to clean project in Android Studio?

Note Never clean your project using the Build -> Clean Project. Instead of cleaning your project it will increase the size of it. Update clean has been replaced by cleanBuildCache in the recent versions of Android Studio.

How do I clean my project?

Go to Menu option –> Select Project –> click Clean… Note: The same can also be achieved by clicking CTRL + S (save) simultaneously in Eclipse IDE.


3 Answers

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.

like image 174
stefan Avatar answered Oct 08 '22 01:10

stefan


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.

like image 6
youpilat13 Avatar answered Oct 13 '22 00:10

youpilat13


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.

like image 3
Tomasz Kryński Avatar answered Oct 13 '22 01:10

Tomasz Kryński