Android gradle单独的res/文件夹构建



我正在尝试按国家生成一个apk,其中每个国家特定的可提取项都在国家代码/res/

(目前有两个国家,"美国"one_answers"it")而公共资源只是un-res/

res/drawable/generic.png
res/drawable/specific.png
it/res/drawable/specific.png
us/res/drawable/specific.png

这是我的构建文件

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'
dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}
android {
    compileSdkVersion 15
    buildToolsVersion "18.1.0"
    flavorGroups "lang"
    productFlavors {
        it {
            flavorGroup "lang"
        }
        us {
            flavorGroup "lang"
        }
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
        it{
            res.srcDirs = ['it/res']
        }
        us{
            res.srcDirs = ['us/res']
        }
        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')
        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }

    signingConfigs {
        release {
            storeFile file("signing/mykey.keystore")
            storePassword "******"
            keyAlias "myalias"
            keyPassword "******"
        }
    }
    buildTypes {
        debug {
            versionNameSuffix "-DEBUG"
            packageNameSuffix ".debug"
        }
        release {
            debuggable false
            signingConfig signingConfigs.release
        }
        debugRelease.initWith(buildTypes.release)
        debugRelease {
            debuggable true
            packageNameSuffix '.debugrelease'
            signingConfig signingConfigs.release
        }
   }

}

但它未能构建,并出现错误:java.lang.StackOverflowError你能帮我设置这个版本吗?非常感谢

我终于成功了,这篇博客文章对我帮助很大:http://apporia.blogspot.fr/2013/11/gradle-and-flavor-groups.html

stackOverflowError错误来自于风味名称,我只是将"it"重命名为"Italia",将"us"重新命名为"usa",构建成功了,我花了几个小时才弄清楚。。。

最新更新