Skip to content Skip to sidebar Skip to footer

With Two Res Directories Per Build Variant, Gradle Stopped Tracking Changes In Resource Files

I, quite innocently, switched to using different app icons for each product flavour along these lines: sourceSets.production { res.srcDirs = ['res', 'res-production'] } source

Solution 1:

Ok, got this fixed. It turned out to be a small problem in my build.gradle.

What helped me was trying to upgrade to Gradle plugin 0.9.0, after which I started getting errors like these:

* What went wrong:
A problem occurred configuring root project 'MyProject'.
> SourceSets 'debug' and 'main' use the same file/folder for'res': /path/to/MyProject/res

Well, I simply tried removing res.srcDirs = ['res'] from main sourceSets, and that was it.

sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        // res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    }
    // ...
}

I left the rest of the sourceSets definitions untouched (res.srcDirs = ['res', 'res-beta'] for sourceSets.beta and so on).

Everything works again: the build type (or product flavour) specific custom icons are in use, and Gradle once again correctly notices changes to resource files (e.g. layouts) in incremental builds!

Possibly the root cause here was using "old project structure" and build.gradle that was originally generated by Eclipse. In any case, studying source sets and project structure more carefully in the User Guide might have helped too.

Solution 2:

I have the several build flavors for the same app with some changes, icons & splash screens. Each flavor have its own res folder. When I build the apps, each apk sizes around 50 mb :(.

So I fixed the issue by updating the build.gradle file with the following

`    sourceSets {
        main {
//            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
//            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
        prod {
            manifest.srcFile 'prod/AndroidManifest.xml'
            resources.srcDirs = ['src/prod/res']
        }
        dev {
            manifest.srcFile 'dev/AndroidManifest.xml'
            resources.srcDirs = ['src/dev/res']
        }

}`

In the above, I commented resources.srcDirs = ['src'] and added

           `prod {
                manifest.srcFile 'prod/AndroidManifest.xml'
                resources.srcDirs = ['src/prod/res']
            }
            dev {
                manifest.srcFile 'dev/AndroidManifest.xml'
                resources.srcDirs = ['src/dev/res']
            }`

Post a Comment for "With Two Res Directories Per Build Variant, Gradle Stopped Tracking Changes In Resource Files"