构建变体和不同的AppIcons

时间:2017-01-27 07:21:55

标签: android-studio icons android-gradle android-resources

除了AppIcon之外,我有2个使用相同图像和资源的应用。 一个常见的解决方案是为src下的每个应用程序创建一个单独的文件夹,并配置gradle以使用相应的文件夹。

在我的情况下,99%的资源都来自两个应用程序,但只有appicon是不同的。

我是否还必须使用具有不同res文件夹的机制,或者还有一种更简单的方法,所以我不必克隆所有资源?

我以为我可以这样做: 我有一个AndroidManifest条目如下:

<application android:name="bla.bla.MyApplication" android:largeHeap="true" android:icon="@drawable/icon" android:label="@string/app_name">

我可以在gradle中覆盖名称,如下所示,这很好用:

demo {
    resValue "string", "app_name", "This is the Demo"
    resValue "drawable", "icon", "demoicon"
}

有没有办法以同样的方式覆盖图标名?

正如你在上面的片段中看到的那样,我已经尝试过,但是我得到了一个 重复资源错误,因为我在res / drawable下保存的demoicon是自动生成的。

2 个答案:

答案 0 :(得分:0)

如果你的口味就像生产一样:

android.sourceSets.production 
{
    res.srcDirs = ['res', '/path/to/production/res/dir']
}

然后在你的/ path / to / production / res / dir / drawable- *中你会得到你的启动器图标。

答案 1 :(得分:0)

以下列方式解决:

我不想为不同的构建类型克隆res文件夹,只是为了更改app-icon。

可以使用manifestPlaceholders来完成:

在我的build.gradle中:

buildTypes {
demo {

            manifestPlaceholders = [iconpath:"@drawable/icon_timeline_test"]
        }

它将替换AndroidManifest中的图标,引用如下:

 android:icon="${iconpath}" 
相关问题