0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ComposeとRoborazziでGoogle Playストア用の画像を生成してみた

0
Last updated at Posted at 2026-07-11

はじめに

個人でAndroidアプリを開発していたとき、Google Playストア用のアイコンやスクリーンショットなどの画像アセットを用意するのが面倒だと感じました。

アプリのUIやデザインを変更するたびに、Figmaなどの外部ツール側も更新して、画像をエクスポートし直すのは正直手間です。個人的には、自分だけの開発だからこそ、慣れ親しんだComposeのコードとGitの環境だけで完結させたいと考えました。

そこで、普段UIテストで利用しているRoborazziを画像生成ツールとして流用してみました。やってみたら便利だったので、設定方法や良かったことをこの記事にまとめます。

実装コード

使い慣れたComposeで画像用にUIを描画し、Roborazziの機能を使ってローカルに画像を出力します。

Robolectricの @Config(qualifiers = "...") により画像のサイズや端末の言語設定をテストケースごとに設定できます。以下のようなUnitテストを作成し、実行するだけで、指定したディレクトリに画像を生成できます。

@RunWith(RobolectricTestRunner::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
class CapturePlayStoreImages {
    @get:Rule
    val composeTestRule = createAndroidComposeRule<ComponentActivity>()

    // Google Playストア用アイコン(512px × 512px)を生成する(128dp × 4(xxxhdpi) = 512px)
    @Config(qualifiers = "w128dp-h128dp-xxxhdpi")
    @Test
    fun captureIcon() {
        composeTestRule.setContent {
            // ここに画像として出力したいComposableの実装を配置する
            AppIcon()
        }
        composeTestRule.onRoot().captureRoboImage(
            filePath = "play-store/icon.png",
        )
    }

    // 通常のスマートフォンサイズのスクリーンショットを生成
    @Config(qualifiers = "w414dp-h736dp-xxhdpi")
    @Test
    fun capturePhone_1() {
        // ...
    }

    // 言語を日本語(ja)に設定して、スクリーンショットを生成
    @Config(qualifiers = "ja-w414dp-h736dp-xxhdpi")
    @Test
    fun capturePhone_1_ja() {
        // ...
    }
}

良かったこと

  • Androidプロジェクト内でGoogle Playストア用の画像を管理・生成できるようになり、Figmaなどの外部ツールの利用が減る
  • UIコンポーネントやカラー定義を変更した際、テストを再実行するだけで画像が更新されるため、ストア画像の更新忘れを防止できる

まとめ

  • Roborazziをテスト用ではなく、画像生成の用途で利用しても便利
  • Robolectricの @Config を活用すれば、Roborazziで生成する画像の設定が可能
  • Androidプロジェクト内でGoogle Playストア用の画像を管理したい場合、Roborazziは有用

参考文献

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?