每构建变量2资源目录,停止摇篮跟踪资源文件的变化 [英] With two res directories per build variant, Gradle stopped tracking changes in resource files

查看:199
本文介绍了每构建变量2资源目录,停止摇篮跟踪资源文件的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我,很天真地转用<一个href=\"http://stackoverflow.com/questions/18460095/how-to-provide-different-launcher-icon-per-product-flavour\">different对沿着这些线路的每个产品的风味的应用程序图标:

I, quite innocently, switched to using different app icons for each product flavour along these lines:

sourceSets.production {
    res.srcDirs = ['res', 'res-production']
}

sourceSets.beta {
    res.srcDirs = ['res', 'res-beta']
}

sourceSets.internal {
    res.srcDirs = ['res', 'res-internal']
}

事情是,在这之后,摇篮停止注意到任何布局文件的变化,如 RES /布局/ activity_faq.xml 和< STRONG>需要一个干净的构建每次后,如果我想包括在APK我的XML的变化。

Thing is, after that, Gradle stopped noticing changes in any layout files, such as res/layout/activity_faq.xml, and requires a clean build each time, if I want my XML changes to be included in the APK.

我首先想到这是一款Android工作室的问题,但实际上,我可以用纯摇篮重现,在命令行上,只是看着在出现建/ RES /所有文件/内部/调试/布局

I first thought this was an Android Studio problem, but in fact I can reproduce it with pure Gradle, on the command line, simply looking at the files that appear under build/res/all/internal/debug/layout.

当我运行 ./ gradlew assembleInternalDebug ,它输出:

:compileInternalDebugNdk UP-TO-DATE
:preBuild UP-TO-DATE
:preInternalDebugBuild UP-TO-DATE
:prepareInternalDebugDependencies
:compileInternalDebugAidl UP-TO-DATE
:compileInternalDebugRenderscript UP-TO-DATE
:generateInternalDebugBuildConfig UP-TO-DATE
:mergeInternalDebugAssets UP-TO-DATE
:mergeInternalDebugResources
:processInternalDebugManifest UP-TO-DATE
:processInternalDebugResources UP-TO-DATE
:generateInternalDebugSources UP-TO-DATE
:compileInternalDebugJava UP-TO-DATE
:preDexInternalDebug UP-TO-DATE
:dexInternalDebug UP-TO-DATE
:processInternalDebugJavaRes UP-TO-DATE
:validateDebugSigning
:packageInternalDebug UP-TO-DATE
:assembleInternalDebug UP-TO-DATE

BUILD SUCCESSFUL

在这里, processInternalDebugResources 显示为 UP-TO-DATE ,虽然我认为它应该的不可以是,当有改变资源文件。图标每味改变之前,类似的摇篮输出, processInternalDebugResources 中的的显示了最新的。

Here, processInternalDebugResources is shown to be UP-TO-DATE, while I think it should not be, when there are changed resource files. Before the icon-per-flavour change, in similar Gradle output, processInternalDebugResources was not shown up-to-date.

问题是,什么办法来解决这个问题,还是我偶然发现在Android的摇篮插件中的错误?

我的的build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.3'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}
dependencies {
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.google.guava:guava:15.0'
    compile 'com.netflix.rxjava:rxjava-core:0.14.2'
    compile 'com.netflix.rxjava:rxjava-android:0.14.2'
    compile 'com.squareup.okhttp:okhttp:1.2.1'

    compile 'com.android.support:support-v4:13.0.0'
    compile 'com.android.support:support-v13:13.0.0'
}

android {
    compileSdkVersion 19
    buildToolsVersion "19"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
    }

    productFlavors {
        production {
            packageName "fi.company.app"
        }
        beta {
            packageName "fi.company.app.beta"
        }
        internal {
            packageName "fi.company.app.internal"
        }
    }

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

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }

    // Custom res directories for different flavors; used for 
    // setting different app icon.

    sourceSets.production {
        res.srcDirs = ['res', 'res-production']
    }

    sourceSets.beta {
        res.srcDirs = ['res', 'res-beta']
    }

    sourceSets.internal {
        res.srcDirs = ['res', 'res-internal']
    }

    signingConfigs {
        release {
            // ...
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
            // ...
        }
    }
}

摇篮1.9; Android的摇篮插件0.7.3。

Gradle 1.9; Android Gradle plugin 0.7.3.

修改:对于其他的原因,我从产品口味切换到自定义生成类型了解我的应用程序图标的定制需求。这个问题仍然存在,所以至少这不是产品的风味特殊。

Edit: For other reasons, I switched from product flavours to custom build types for my app icon customisation needs. This problem still remains, so at least this isn't product flavour specific.

推荐答案

好,我知道这个固定。它原来是一个小问题,我的的build.gradle

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

什么帮助我试图升级到摇篮插件0.9.0,在这之后我开始喜欢这些错误:

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

好吧,我只是尝试的删除 res.srcDirs = ['水库'] 从主sourceSets ,那就是它。

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']
    }
    // ...
}

我离开了sourceSets定义其余不变( res.srcDirs = ['资源','RES-β'] sourceSets。测试版等)。

一切再次工作:构建类型(或产品风味)特定的自定义图标都在使用,并且摇篮再次注意到正确更改资源文件(例如,布局)的增量构建

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!

(我证实问题确实是我的配置用摇篮的插件版本0.8.1,0.9.0和0.9.3与我改变了的build.gradle 。事实上,在插件的变化是不是解决了这个问题,即使0.9.0是开始给我有用的错误消息的版本。)

(I verified that the problem indeed was in my config by testing with Gradle plugin versions 0.8.1, 0.9.0 and 0.9.3 with my changed build.gradle. Indeed, changes in the plugin were not what fixed this, even if 0.9.0 was the version that started giving me the useful error message.)

可能在根源在这里使用的老项目结构和的build.gradle 最初由Eclipse的产生。在任何情况下,仔细研究源集和项目结构在用户指南可能也有帮助。

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.

这篇关于每构建变量2资源目录,停止摇篮跟踪资源文件的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆