LoginSignup
4
4

More than 5 years have passed since last update.

似たようなAndroidアプリを同一端末にインストール出来るようにする

Last updated at Posted at 2016-09-30

名称未設定.png

:pencil2: 追記

Android Studio 3からの設定方法を反映させました。

🔰 はじめに

機能はほぼ同じで、向き先のURLが違ったりするapkを作りたいと思います。
Android(Studio)の対応が分からなかったので今回調べてみました🤔

🖥 環境

  • Android Studio 2.1.3
  • Kotlin 1.0.1-2
  • Gradle 2.14.1

🛠 設定

対応方法としては、Flavorの機能を利用してpackageNameを変更するという方針をとっていきます。

productFlavorsの設定

app/build.gradle
android{
    productFlavors {
        www {

        }
        dev {
            applicationIdSuffix = '.dev'
        }
        stg {
            applicationIdSuffix = '.stg'
        }
    }
}

追記ここから :arrow_down_small:

Android Studio 3から

app/build.gradle
android{

    flavorDimensions "Production", "staging", "develop"

    productFlavors {
        www {
             dimension "Production"
        }
        dev {
            applicationIdSuffix = '.dev'
            dimension "staging"
        }
        stg {
            applicationIdSuffix = '.stg'
            dimension "develop"
        }
    }
}

バージョン3からは、すべてのフレーバが名前付きフレーバディメンションに属している必要があります。
そうしないと、ビルドエラーが発生します。

追記ここまで :arrow_up_small:


例えばこんな感じに設定します。

あとはFlavor毎にアプリの表示名を明示的に変更してあげればいいと思います。

serc/dev/res/string.xml
<resources>
    <string name="app_name">[dev]application</string>
</resources>

ビルドをするときは build Valiants で切り替えてあげればOKです。
build Valiants はIDEの左下にあって目立たないですね😰

🔗 Refs

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