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?

More than 3 years have passed since last update.

Codemagicでリポジトリにないファイルを追加してビルドする

Posted at

Codemagicでは簡単にFlutterアプリをビルド・配信できますが、google-services.jsonなどのリポジトリに登録されていない機密ファイルをビルドに含めるのが少し面倒なので、記載しておきます。

考え方

以下リンク先に記載の通りですが、ファイルを文字列に変換し環境変数として持っておき、ビルド前にファイルに再変換する、というステップを踏みます。
https://blog.codemagic.io/how-to-load-firebase-config-in-codemagic-with-environment-variables/

  1. 追加したいファイルをBase64エンコードします。
  2. 環境変数にエンコードした文字列を設定します。
  3. pre-buildスクリプトで、環境変数からBase64デコードしてファイルを出力します。

実際にやってみる

リポジトリにコミットされていない機密ファイルをBase64エンコードします。
Windowsではcertutilを使うとできます。標準で入っています。

certutil -encode messages.json messages.txt

エンコードした文字列を環境変数に設定します。

image.png

pre-buildスクリプトを設定します。
pre-buildスクリプトの入力欄は、Buildの1つ上の「+」ボタンを押すと出てきます。
ここに環境変数をファイルに変換するスクリプトを記載します。

# !/bin/sh
echo $MESSAGES | base64 --decode > $FCI_BUILD_DIR/assets/data/messages.json

image.png

以上で設定は終わりです。
実際にビルドして動作を確認します。

おしまい。

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?