0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

BuildVariantsごとのGitSecretの扱い方

Last updated at Posted at 2022-07-07

はじめに

GitでRepositoryの管理をする際にAPIのkeyなどそのままPushしないためにGitSecretを使う方が多いと思うのですが...
https://github.com/awslabs/git-secrets

Android開発でステージングかリリース環境かでKeyが違う...って時に困ったのでメモです。
*多分もっとスマートなやり方があります...ゴリ押し手法です...

やってみた

まずbuild.gradleで設定したBuildVariantsごとにpropertiesファイルを生成しましょう。

staging.properties
production.properties

次に各ファイルの中にそれぞれのKey情報を書き込みます。

API_KEY = "hogehogehogehoge"
SECRET_ID = "fugafugafuga"

完成したら今度はbuild.gradleの変更です。

 def apiKeyPropertiesFile = rootProject.file("staging.properties")
 def apiKeyProperties = new Properties()
 apiKeyProperties.load(new FileInputStream(apikeyPropertiesFile))

 resValue "string", "API_KEY", apiKeyProperties['API_KEY']
 buildConfigField("String", "SECRET_ID", apiKeyProperties['SECRET_ID'])

これをBuildVariantsごとに設定してもらえればコード内で同じ変数名でも各環境で個別のキー情報を使用できます。

最後に作成したpropertiesにgit secretを適用することだけ忘れずに...

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?