
【CI/CD】BitriseでDeployGateをAndroidでやってみた
2021.12.20
第1弾~はじめに~

(株)ライトコードの笹川(ささがわ)です!
弊社ブログの中で、あまりCIについて触れているものがないので、先陣きっていくつか書いていこうかと思います!
CIやCDについてのそもそもの説明については、探せば多く出てくると思いますので省略します。
なぜBitrise(ビットライズ)なのか?
有名なところでいうと「CircleCI」や「TravisCI」など「CI」は、多くのサービスやツールがありますが、Bitriseには他とは大きく違ったメリットがあります。
それは、「無料でiOSアプリケーションのビルドが出来る!」 というところです。
しかし、今回のテーマは、「Android(アンドロイド)」。
そうです!
次の記事は、「BitriseでDeployGateなiOSのこと」を書きます!(予告)
また、今回は、「会員登録の手順」は、探せば多く出てくると思いますのでこちらも省きます。
早速設定を始めてみましょう!
Androidビルドの環境はこちら
- compileSdkVersion 28
- buildToolsVersion '28.0.3'
- minSdkVersion 21
- targetSdkVersion 26
- keystoreはそれぞれリポジトリに含む
設定してみる
公式ドキュメント通りに進めてみます。
【公式ドキュメント】
https://devcenter.bitrise.io/jp/getting-started/getting-started-with-android-apps/
すると、いきなり install-missing-android-tools でエラーが!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | +------------------------------------------------------------------------------+ | (4) install-missing-android-tools@2.3.5 | +------------------------------------------------------------------------------+ | id: install-missing-android-tools | | version: 2.3.5 | | collection: https://github.com/bitrise-io/bitrise-steplib.git | | toolkit: go | | time: 2019-05-25T10:31:00Z | +------------------------------------------------------------------------------+ | | INFO[10:31:00] Start installing (golang) with apt-get INFO[10:31:00] * [OK] Step dependency (go) installed, available. Configs: - GradlewPath: ./gradlew - AndroidHome: /opt/android-sdk-linux - NDKRevision: Preparation Set executable permission for gradlew Installing NDK bundle NDK home: /opt/android-ndk Cleaning Downloading Initialize Android SDK Ensure android licences Ensure required Android SDK components Retrying... Failed to ensure android components, error: output: > Configure project :app NDK is missing a "platforms" directory. If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to /opt/android-ndk. If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning. NDK is missing a "platforms" directory. If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to /opt/android-ndk. If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning. FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring project ':app'. > java.lang.NullPointerException (no error message) * Try: Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Exception is: org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':app'. ~省略~ * Get more help at https://help.gradle.org BUILD FAILED in 1s error: exit status 1 | | +---+---------------------------------------------------------------+----------+ | x | install-missing-android-tools@2.3.5 (exit code: 1) | 172 sec | +---+---------------------------------------------------------------+----------+ | Issue tracker: ...bitrise-steplib/steps-install-missing-android-tools/issues | | Source: ...://github.com/bitrise-steplib/steps-install-missing-android-tools | +---+---------------------------------------------------------------+----------+ |
よく見るとWarinigが出ています。
1 2 3 4 5 6 7 | NDK is missing a "platforms" directory. If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to /opt/android-ndk. If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning. NDK is missing a "platforms" directory. If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to /opt/android-ndk. If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning. |
どうやら、NDKのインストールがうまく行ってない様子です。
NDKのインストール
では、NDKのインストールの設定もしてみましょう。
https://developer.android.com/ndk/downloads
AndroidのNDKの最新安定バージョンは、上記URLを参考に下記のように指定をしてみましょう。
1 2 3 | - install-missing-android-tools@: inputs: - ndk_revision: 19c |
これで、ReBuildをしたらどうでしょう?
実は、笹川の環境下では、これでもダメでした。
Fastlaneでビルドしてみる
公式ドキュメントの通りじゃビルドが出来ないので、思い切ってFastlaneを導入してみました。
laneはこちら
1 2 3 4 5 6 7 8 9 | desc "Deploy to Develop" lane :deploy_develop do gradle(task: "assembleDebug") deploygate( api_token: ENV['DEPLOYGATE_API_KEY'], user: ENV['DEPLOYGATE_USER'], message: "Debug Build \n Last Commit Message is \n ( #{ENV['COMMIT_MESSAGE']} )", ) end |
ビルド自体はうまくいきました!
DeployGateへのアップロードも問題なく出来るようになりました。
問題発生
しかし、ここでまた一つ問題が出てきます。
Deploy to Bitrise.io で、Artifactsがうまく保存されません。
GradleRunnerを使ってみる
Bitriseには、gradlewコマンドをそのまま実行するためのGradleRunnerというアイテムもあります。
こちらに先程、laneで指定したのと同じ assembleDebug を設定します。
どうやらこれが最適解だったようです。
Artifactsがうまく保存されないのを深掘りしてみる
デフォルトのDeploy to Bitrise.ioの設定
1 | - deploy-to-bitrise-io: {} |
設定画面上では、 Deploy directory or file path には、 $BITRISE_DEPLOY_DIR と設定されています。
こちらをfastlaneの主力先を $BITRISE_DEPLOY_DIR と変えさえすれば、 fastlane でも問題なくArtifactsに保存されました。
さいごに
Bitriseの公式ドキュメントは、日本語の整備もされていますし、GUIで設定できることが多いので素晴らしいツールです。
しかしながら、ドキュメントに載っていないもの情報は、あまりQiitaやブログ記事でも多いのですが、エラーが出た時にどう対応したかという記事は多くないです。
今日、紹介したのは、笹川の個人ブログで取り上げたこちらの記事を深掘りした記事となります。
Bitrise日本法人ブログでも引用していただき、Bitriseの公式ブログの方でもちょっとだけ紹介されたりなど少し反響がありましたので、この場を借りて詳細な内容をアウトプットさせていただきました。

こちらの記事もオススメ!
関連記事
オススメ本
最終的に出来上がったymlファイル
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | --- format_version: '7' default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git project_type: android workflows: debug-deploy: steps: - activate-ssh-key@4.0.3: run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}' - git-clone@4.0.14: {} - cache-pull@2.0.1: {} - gradle-runner@1.9.0: inputs: - gradle_task: assembleDebug - gradlew_path: "$PROJECT_LOCATION/gradlew" - deploygate--upload-app-bitrise-step@1.0.1: inputs: - owner_name: xxxxx - app_path: "$BITRISE_APK_PATH" - message: "[$BITRISE_BUILD_NUMBER] Debug Build [$BITRISE_GIT_BRANCH] ($BITRISE_GIT_MESSAGE)" - api_key: "$DEPLOYGATE_API_KEY" - deploy-to-bitrise-io@1.4.1:{} - cache-push@2.2.0: {} - slack@3.1.2: inputs: - webhook_url: "$SLACK_URL" app: envs: - opts: is_expand: false PROJECT_LOCATION: "." - opts: is_expand: false MODULE: app - opts: is_expand: false VARIANT: '' trigger_map: - push_branch: develop workflow: debug-deploy |
書いた人はこんな人

- 新潟生まれ新潟育ち本業はモバイルアプリエンジニア。
日々、猫(犬)エンジニアとして活躍中!
IT技術9月 20, 2023開発効率を少しだけ上げるGithubActionsの便利な使い方
IT技術4月 7, 2023【ISUCON部】ライトコードISUCON部 始動!
IT技術4月 18, 2022【Android】Webでよくみる入力Boxを手作り
IT技術1月 19, 2022【Android】SeekbarでスイッチなUIを作る