LoginSignup
2
1

More than 5 years have passed since last update.

AndroidアプリのApplicationIdをbuildTypes内での変更も考慮してresValueにセットする

Posted at

はじめに

 XML内でApplicationIdを参照する必要があり、gradleでresValueを使って、ApplicationIdをXMLから参照できるよう定義しようとしました。しかし、buildTypes内でApplicationIdが変更されている場合でこのような事を実現しようとした時に少し詰まってしまいました。調査の結果、解決したのでここにメモしておきます。

方法

applicationVariantsを使用して、各variantごとにresValueを設定します。

buildTypes {
    ...
    applicationVariants.all { variant ->
        variant.resValue 'string', 'application_id', applicationId
    }
}

詰まったところ

 gradle内でApplicationIdを変更していなければ上記のようなコードを書く必要はなく、defaultConfig内で

resValue 'string', 'application_id', applicationId

とだけ書いてもうまく動作します。

今回の場合、debugビルド時にapplicationIdSuffixを使い、ApplicationIdを変更していたため、上記のような工夫が必要となりました。

参考

2
1
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
2
1