LoginSignup
22
12

More than 5 years have passed since last update.

Android O(8.0)から登場したAdaptive Iconに自動で環境毎のラベル付けする

Last updated at Posted at 2018-11-21

はじめに

今回は、↓こういう環境ごとのラベル付けをAndroid8から登場したAdaptive Iconでも自動生成して楽しよう!というお話です。 
スクリーンショット 2018-11-21 18.24.50.png

ちなみにAdaptive Iconはこんなやつ

皆さんはアプリを複数環境用意するときにアプリアイコン、どうされているでしょうか?
dev, stg, debugなどの環境ごとに色を変えたり、ラベルを付けたり、もしくはgradle-android-ribbonizer-pluginを使ったり。
ribbonizer-plugin使う方が多いと思いますが、Adaptive Iconに対応していないため上記のようなラベルをつけることが出来ません。

しかし、Adaptive Iconでも楽したい…
ということで、対応していないならライブラリを作ってしまおうかと、調べているうちにAdaptive Iconに対応したライブラリを見つけたのでそのご紹介です。

easylauncher-gradle-plugin

easylauncher-gradle-pluginはAdaptive Iconに対応しており、最初に紹介した画像のようにラベルをつけることが出来ます。
しかもribbonizer-pluginよりも設定がシンプルです。

設定方法

build.gradle
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.akaita.android:easylauncher:1.3.1'
    }
}
  • androidブロック内で定義したbuildTypes、productFlavorsなどのブロックをeasylauncherブロック内に記述し、ラベルを付けたい環境に filters = grayRibbonFilter() を追記します。 redRibbonFilter("pro") のように任意文字列のラベルをつけることも出来ますし、省略すればブロックの環境名が自動的に付与されます。
app/build.gradle
apply plugin: 'com.akaita.android.easylauncher'

// 略

android {
// 略
    buildTypes {

        debug {
            debuggable true
            applicationIdSuffix = '.debug'
            versionNameSuffix = 'd'
            signingConfig signingConfigs.debug
        }
        release {
            debuggable false
            minifyEnabled false
            signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
productFlavors {
        dev {
            applicationIdSuffix = '.dev'
        }
        stg {
            applicationIdSuffix = '.stg'
        }
        pro {

        }
    }

}

easylauncher {
    // "manifest application[android:icon]" is automatically added to the list
    iconNames "@mipmap/ic_launcher_foreground" // Traditional launcher icon
    foregroundIconNames "@mipmap/ic_launcher_foreground" // Foreground of adaptive launcher icon

    defaultFlavorNaming = true // Use flavor name for default ribbon, instead of the type name

    buildTypes {
        debug {}
        release {}
    }

    productFlavors {
        dev {
            // こうすることでグレー色のラベルdevが生成される
            filters = grayRibbonFilter()
        }
        stg {
            filters = greenRibbonFilter()
        }
        pro {}
    }

    variants {
        proDebug {
            // proReleaseにラベルを付けたくない場合はここでdebugのときのみ設定
            filters = redRibbonFilter("pro")
        }
    }
}

設定は以上! ここまで出来たらbuildすることでアイコンが自動生成されます。この設定で生成されたアイコンがこれ↓。カスタマイズ性高く、ほかにもイメージをオーバーレイしたり、サイズ変えたりいろいろ出来ます。気になる方は作者様のページを御覧ください。
スクリーンショット 2018-11-21 18.52.09.png

最後に

Adaptive Iconを活用してるアプリ、あんまり見たことないんですがどうなんでしょう? 意識して見てみると意外と対応してました。
でもひとまず、このライブラリのおかげで引き続き楽できそうです。作者のakaita様、FUJI Goro様に感謝 :pray:

22
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
12