LoginSignup
3
3

More than 5 years have passed since last update.

CircleCIでAndroid SDKがダウンロードできない。

Posted at

Android開発でのCI環境を整えようと、GithubとCircleCIを連携してみたところ早速ビルドに失敗しており、以下のようなメッセージが出ていました。

Checking the license for package Android SDK Build-Tools 25.0.3 in /usr/local/android-sdk-linux/licenses
Warning: License for package Android SDK Build-Tools 25.0.3 not accepted.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> You have not accepted the license agreements of the following SDK components:
  [Android SDK Build-Tools 25.0.3].
  Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
  Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html

どうやらSDKのインストールに失敗しているようでした。

CircleCIのAndroid環境

CircleCIでインストール済みAndroid SDKは以下のようになっています。

たしかにAndroid SDK Build-Tools 25.0.3は初期の環境には含まれていないようでした。
公式ドキュメントによれば、CircleCIのビルド設定によって不足しているパッケージ名を指定してインストールできると書いてあります。

Android Gradle plugin v2.2.0

Android Gradle plugin v2.2.0以降では不足しているパッケージは自動でインストールしてくれるようになったので、上記のCircleCIでのビルド設定は不要になりました。
ビルドびエラーログでは必要なSDKをインストールしようとしてライセンス関係で失敗しているようなのでそこを解決する必要があります。

SDK license agreements

解決方法としては上記のログのリンク先にあります。ここにあるリンクは古いものになっていて、ページを開くとAuto-download missing packages with Gradleというドキュメントへリダイレクトされます。

余談ですが、以前に日本語でサイトを開いていたりすると日本語ページへリダイレクトされてしまう時があります。ところが、この記事はまだ日本語訳されていないようでリダイレクトされても該当記事へたどり着くことができません。表示言語を英語にして開いて下さい。

さて、上記記事に詳しい説明がありますが、Android SDKのインストールにはSDK license agreementsへの同意が必要です。Android Studioで開発している際にSDK ManagerでSDK等をインストールするにはライセンスへの同意が必要となっているはずです。CI環境やコマンドラインでビルドする際に不足しているSDKをインストールするにはこれが必要になるというわけです。

解決方法として、SDK Managerでライセンス同意した時にAndroid Studioが作成するライセンスファイル群を利用します。

  1. Android StudioにてTools > Android > SDK ManagerでAndroid SDKの場所を確認
  2. Android SDKのディレクトリへ移動し、licenses/ディレクトリを確認
  3. licenses/ディレクトリをコピーし、ビルドを行いたい別のマシンのAndroid SDKディレクトリ中に貼り付ける

こうすることで、SDK Managerで手動でライセンス同意することなくAndroid SDKをインストールすることができます。

CicrleCIでの設定

CircleCIの依存解決処理によって、プロジェクト内に配置したライセンスファイルの内容をコピーするようにしました。
プロジェクトルートにcircle.ymlを配置し、例として以下のような内容を書いておきます。

dependencies:
  pre:
    - mkdir $ANDROID_HOME/licenses
    - cat android-sdk-license > $ANDROID_HOME/licenses/android-sdk-license

$ANDROID_HOMEはCircliCIのVM上でAndroid SDKがインストールされたディレクトリです。

これで再度ビルドすると、

Checking the license for package Android SDK Build-Tools 25.0.3 in /usr/local/android-sdk-linux/licenses
License for package Android SDK Build-Tools 25.0.3 accepted.
Preparing "Install Android SDK Build-Tools 25.0.3 (revision: 25.0.3)".
"Install Android SDK Build-Tools 25.0.3 (revision: 25.0.3)" ready.
Finishing "Install Android SDK Build-Tools 25.0.3 (revision: 25.0.3)"
Installing Android SDK Build-Tools 25.0.3 in /usr/local/android-sdk-linux/build-tools/25.0.3
"Install Android SDK Build-Tools 25.0.3 (revision: 25.0.3)" complete.
"Install Android SDK Build-Tools 25.0.3 (revision: 25.0.3)" finished.

必要なAndroid SDKが無事にインストールできたことが確認できました。

3
3
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
3
3