使用不同的资源使用摇篮不同的应用口味

使用不同的资源使用摇篮不同的应用口味

本文介绍了使用不同的资源使用摇篮不同的应用口味的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个Android应用程序,我想有不同的口味。具体来说,我想有2口味和风味各使用不同的字符串(不同的的strings.xml 文件),也许有一些图标不同。


I have an android application and I would like to have different flavors. Specifically I would like to have 2 flavors and for each flavor use different strings (different strings.xml file) and maybe have some icons different.

我试图创造在项目的根文件夹中两个文件夹: flav1 flav2 并用于以下 build.gradle

I have tried creating two folders in the project's root folder: flav1 and flav2 and used the following build.gradle

android {
    compileSdkVersion "Google Inc.:Google APIs:15"
    buildToolsVersion "17.0.0"

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

        instrumentTest.setRoot('tests')
    }

    productFlavors {
        flav1 {
            packageName "com.ic.flav1"
        }

        flav2 {
            packageName "com.ic.flav2"
        }
    }

    android.sourceSets.flav2 {
        res {
            srcDir 'flav2'
        }
        resources {
            srcDir 'flav2'
        }
    }
    android.sourceSets.flav1 {
        res {
            srcDir 'flav1'
        }
        resources {
            srcDir 'flav1'
        }
    }
}

这样做的结果是,没有一个字符串被识别,得到下述类型的多个错误:

The result of this is that none of the strings is recognized, getting multiple errors of the following type:

构建失败:

错误:错误:未发现的资源匹配给定名称(在  contentDescription'与'@字符串/ txt_addr')值。

error: Error: No resource found that matches the given name (at 'contentDescription' with value '@string/txt_addr').

我缺少的东西?应该如何build.gradle是什么?

Am I missing something? How should the build.gradle be?

感谢

推荐答案

解决的办法是添加目录


下的每个相应资源文件夹,所有的弦都承认。

under each corresponding res folder, and all the strings were recognized.

这篇关于使用不同的资源使用摇篮不同的应用口味的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 13:23