• トップ
  • ブログ一覧
  • 【CI/CD】BitriseでDeployGateをAndroidでやってみた
  • 【CI/CD】BitriseでDeployGateをAndroidでやってみた

    笹川(エンジニア)笹川(エンジニア)
    2019.06.18

    IT技術

    第1弾~はじめに~

    秋山笹川先生

    (株)ライトコードの笹川(ささがわ)です!

    弊社ブログの中で、あまりCIについて触れているものがないので、先陣きっていくつか書いていこうかと思います!

    CIやCDについてのそもそもの説明については、探せば多く出てくると思いますので省略します。

    なぜBitrise(ビットライズ)なのか?

    有名なところでいうと「CircleCI」や「TravisCI」など「CI」は、多くのサービスやツールがありますが、Bitriseには他とは大きく違ったメリットがあります。

    それは、「無料でiOSアプリケーションのビルドが出来る!」 というところです。

    しかし、今回のテーマは、「Android(アンドロイド)」

    そうです!

    次の記事は、「BitriseでDeployGateなiOSのこと」を書きます!(予告)

    また、今回は、「会員登録の手順」は、探せば多く出てくると思いますのでこちらも省きます。

    早速設定を始めてみましょう!

    Androidビルドの環境はこちら

    1. compileSdkVersion 28
    2. buildToolsVersion '28.0.3'
    3. minSdkVersion 21
    4. targetSdkVersion 26
    5. keystoreはそれぞれリポジトリに含む

    設定してみる

    公式ドキュメント通りに進めてみます。

    【公式ドキュメント】
    https://devcenter.bitrise.io/jp/getting-started/getting-started-with-android-apps/

    すると、いきなり install-missing-android-tools でエラーが!!

    1+------------------------------------------------------------------------------+
    2
    3| (4) install-missing-android-tools@2.3.5                                      |
    4+------------------------------------------------------------------------------+
    5| id: install-missing-android-tools                                            |
    6| version: 2.3.5                                                               |
    7| collection: https://github.com/bitrise-io/bitrise-steplib.git                |
    8| toolkit: go                                                                  |
    9| time: 2019-05-25T10:31:00Z                                                   |
    10+------------------------------------------------------------------------------+
    11|                                                                              |
    12INFO[10:31:00] Start installing (golang) with apt-get       
    13INFO[10:31:00]  * [OK] Step dependency (go) installed, available. 
    14Configs:
    15- GradlewPath: ./gradlew
    16- AndroidHome: /opt/android-sdk-linux
    17- NDKRevision: 
    18Preparation
    19Set executable permission for gradlew
    20Installing NDK bundle
    21NDK home: /opt/android-ndk
    22Cleaning
    23Downloading
    24Initialize Android SDK
    25Ensure android licences
    26Ensure required Android SDK components
    27Retrying...
    28Failed to ensure android components, error: output: > Configure project :app
    29NDK is missing a "platforms" directory.
    30If you are using NDK, verify the ndk.dir is set to a valid NDK directory.  It is currently set to /opt/android-ndk.
    31If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
    32NDK is missing a "platforms" directory.
    33If you are using NDK, verify the ndk.dir is set to a valid NDK directory.  It is currently set to /opt/android-ndk.
    34If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
    35FAILURE: Build failed with an exception.
    36* What went wrong:
    37A problem occurred configuring project ':app'.
    38> java.lang.NullPointerException (no error message)
    39* Try:
    40Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    41* Exception is:
    42org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':app'.
    43
    44~省略~
    45
    46* Get more help at https://help.gradle.org
    47BUILD FAILED in 1s
    48error: exit status 1
    49|                                                                              |
    50+---+---------------------------------------------------------------+----------+
    51| x | install-missing-android-tools@2.3.5 (exit code: 1)            | 172 sec  |
    52+---+---------------------------------------------------------------+----------+
    53| Issue tracker: ...bitrise-steplib/steps-install-missing-android-tools/issues |
    54| Source: ...://github.com/bitrise-steplib/steps-install-missing-android-tools |
    55+---+---------------------------------------------------------------+----------+

    よく見るとWarinigが出ています。

    1NDK is missing a "platforms" directory.
    2If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to /opt/android-ndk.
    3If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
    4
    5NDK is missing a "platforms" directory.
    6If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to /opt/android-ndk.
    7If 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- install-missing-android-tools@:
    2inputs:
    3- ndk_revision: 19c

    これで、ReBuildをしたらどうでしょう?

    実は、笹川の環境下では、これでもダメでした。

    Fastlaneでビルドしてみる

    公式ドキュメントの通りじゃビルドが出来ないので、思い切ってFastlaneを導入してみました。

    laneはこちら

    1  desc "Deploy to Develop"
    2  lane :deploy_develop do
    3    gradle(task: "assembleDebug")
    4    deploygate(
    5      api_token: ENV['DEPLOYGATE_API_KEY'],
    6      user: ENV['DEPLOYGATE_USER'],
    7      message: "Debug Build \n Last Commit Message is \n ( #{ENV['COMMIT_MESSAGE']} )",
    8    )
    9  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の公式ブログの方でもちょっとだけ紹介されたりなど少し反響がありましたので、この場を借りて詳細な内容をアウトプットさせていただきました。

    秋山笹川先生
    冒頭で述べた通り、次回は、iOSで同じくBitriseを利用したDeploy方法を紹介しようかと思います!

    こちらの記事もオススメ!

    featureImg2020.08.14スマホ技術 特集Android開発Android開発をJavaからKotlinへ変えていくためのお勉強DelegatedPropert...

    featureImg2020.07.17ライトコード的「やってみた!」シリーズ「やってみた!」を集めました!(株)ライトコードが今まで作ってきた「やってみた!」記事を集めてみました!※作成日が新し...

    関連記事

    featureImg2019.06.18【CI/CD】BitriseでDeployGateをAndroidでやってみた第1弾~はじめに~笹川先生(株)ライトコードの笹川(ささがわ)です!弊社ブログの中で、あまりCIについて触れているもの...

    featureImg2019.06.20【CI/CD】BitriseでDeployGateなiOSをFastlane matchでやってみる第2弾~はじめに~笹川先生(株)ライトコードの笹川(ささがわ)です!CIシリーズ第2弾です!引き続き、Bitriseの...

    featureImg2019.07.02【CI/CD】BitriseでDeployGateなFlutterのAndroidとiOSをやってみる第3弾~はじめに~笹川先生(株)ライトコードの笹川(ささがわ)です!CIシリーズ第3弾です!引き続きBitriseの使...

    オススメ本

    iOSアプリ開発自動テストの教科書 〜XCTestによる単体テスト・UIテストから,CI/CD,デバッグ技術まで
    iOSアプリ開発自動テストの教科書 〜XCTestによる単体テスト・UIテストから,CI/CD,デバッグ技術まで

     

    最終的に出来上がったymlファイル

    1---
    2format_version: '7'
    3default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
    4project_type: android
    5workflows:
    6  debug-deploy:
    7    steps:
    8    - activate-ssh-key@4.0.3:
    9        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    10    - git-clone@4.0.14: {}
    11    - cache-pull@2.0.1: {}
    12    - gradle-runner@1.9.0:
    13        inputs:
    14        - gradle_task: assembleDebug
    15        - gradlew_path: "$PROJECT_LOCATION/gradlew"
    16    - deploygate--upload-app-bitrise-step@1.0.1:
    17        inputs:
    18        - owner_name: xxxxx
    19        - app_path: "$BITRISE_APK_PATH"
    20        - message: "[$BITRISE_BUILD_NUMBER] Debug Build [$BITRISE_GIT_BRANCH] ($BITRISE_GIT_MESSAGE)"
    21        - api_key: "$DEPLOYGATE_API_KEY"
    22    - deploy-to-bitrise-io@1.4.1:{}
    23    - cache-push@2.2.0: {}
    24    - slack@3.1.2:
    25        inputs:
    26        - webhook_url: "$SLACK_URL"
    27app:
    28  envs:
    29  - opts:
    30      is_expand: false
    31    PROJECT_LOCATION: "."
    32  - opts:
    33      is_expand: false
    34    MODULE: app
    35  - opts:
    36      is_expand: false
    37    VARIANT: ''
    38trigger_map:
    39- push_branch: develop
    40  workflow: debug-deploy

     

    笹川(エンジニア)

    笹川(エンジニア)

    おすすめ記事