LoginSignup
1
0

More than 5 years have passed since last update.

(失敗報告) AndroidアプリのUIテストをDockerコンテナ上で実施する

Last updated at Posted at 2016-06-10

はじめに

Androidアプリのビルド、Emulator用AVDの作成、Emualtorの起動、UIテストをコンテナ上で実施する実験をしたが失敗した。
Emulatorの起動のところでKVMでエラーになり、どうやらコンテナ上で動作させるのは無理または一般的ではないようなので、ここで中断とする。

結論

CLIでのEmulator起動+テストは可能だが、コンテナ上での実施は一般的でないようなので別の方法を検討したほうが良い。
今後は、Emulator無しで可能なテストと、Emulator有りで可能なテストのそれぞれで調査をしていく。
また、Emulator有りのテストについては、コンテナ以外の方法として、
Sakura VPSでのVM on VMや、自宅サーバ上でのテストが候補に挙げられる。

環境

ホストOS

$ docker -v
Docker version 1.7.1, build 786b29d/1.7.1

コンテナ内

# uname -a
Linux a7f955bd9c05 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 GNU/Linux
# java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-1~bpo8+1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

コンテナの作成

コンテナの作成。

sudo docker pull gfx2015/android:latest
sudo docker run -it gfx2015/android  

追加のAndroid-SDKを追加

android update sdk -u -a -t android-20
android update sdk -a --no-ui --filter source-22      
android update sdk -a --no-ui --filter android-22
android update sdk -a --no-ui --filter sys-img-armeabi-v7a-android-22,sys-img-x86_64-android-22

ビルドの確認

cd /home
git clone http://xxxxxxxxxxxxxxxxxxxx.git
./gradlew clean && ./gradlew build

AVDの作成

android create avd --name myandroid22 -t "android-22" --abi "default/x86_64"

Emulatorの起動

AVDを作成できたので、Emulatorを起動させる。
kvmが必要らしい。

root@b1aeb9a769e1:/home# emulator -avd myandroid22 -force-32bit
emulator: WARNING: Increasing RAM size to 1GB
emulator: ERROR: x86_64 emulation currently requires hardware acceleration!
Please ensure KVM is properly installed and usable.
CPU acceleration status: KVM is not installed on this machine (/dev/kvm is missing).

kvmのインストール。

root@b1aeb9a769e1:/home# apt-get install kvm

kvmがうまくインストールされていない様子。
ただ、そもそもLXC上なので、ここでkvmが動作するのかが不明。

root@b1aeb9a769e1:/home# emulator -avd myandroid22 -force-32bit
emulator: WARNING: Increasing RAM size to 1GB
emulator: ERROR: x86_64 emulation currently requires hardware acceleration!
Please ensure KVM is properly installed and usable.
CPU acceleration status: KVM is not installed on this machine (/dev/kvm is missing).

とりあえず、コンテナがデーモンモードでないこと、
権限無視フラグが付いていないので、それをつけてデーモンが動作する状態にして再試行する。

sudo docker commit b1aeb9a769e1 temp/android_emulator
sudo docker run -d temp/android_emulator /sbin/init
sudo docker exec -it a7f955bd9c053f22a8838d71c86c00466987ff4cc278cb21ff1cd625e6ab232e /bin/bash

KVMの再インストール。

apt-get remove kvm
apt-get install kvm

やはりダメ。
KVM kernel moduleと言っているので、
もしかすると、docker本体が動いているホストOS側にKVMカーネルモジュールをインストールすれば
動くのかもしれないけれども、ここらへんでやめておく。

root@a7f955bd9c05:/# kvm 
Could not access KVM kernel module: No such file or directory
failed to initialize KVM: No such file or directory
root@a7f955bd9c05:/# 

最初に実施したときの試行錯誤

コンテナ作成。

sudo docker pull gfx2015/android:latest
sudo docker run -it gfx2015/android  

追加SDKインストール。

android update sdk -u -a -t android-20
android update sdk -u -a -t platform-tools
android update sdk -u -a -t build-tools-20.0.0

AVDを作成するためのターゲットを確認。

root@0741f65689c0:/home/android_program# android list targets
Available Android targets:
----------
id: 1 or "android-20"
     Name: Android 4.4W.2
     Type: Platform
     API level: 20
     Revision: 2
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
 Tag/ABIs : no ABIs.
----------
id: 2 or "android-23"
     Name: Android 6.0
     Type: Platform
     API level: 23
     Revision: 3
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
 Tag/ABIs : no ABIs.
root@0741f65689c0:/home/android_program# 

AVDを作成してみる・・・失敗。

root@0741f65689c0:/home/android_program# android create avd -n avd_android4_4 -t 1
Valid ABIs: no ABIs.
Error: This platform has more than one ABI. Please specify one using --abi.
root@0741f65689c0:/home/android_program# 

ABIをインストールしてみる・・・SDKの依存性があるらしい。

android update sdk -a --no-ui --filter sys-img-armeabi-v7a-android-22,sys-img-x86_64-android-22
Installing Archives:
  Preparing to install archives
  Skipping 'ARM EABI v7a System Image, Android API 22, revision 1'; it depends on 'SDK Platform Android 5.1.1, API 22, revision 2' which was not installed.
  Skipping 'Intel x86 Atom_64 System Image, Android API 22, revision 5'; it depends on 'SDK Platform Android 5.1.1, API 22, revision 2' which was not installed.
  Done. Nothing was installed.

SDKをインストールした・・・成功

android update sdk -a --no-ui --filter source-22      
Installing Archives:
  Preparing to install archives
  Downloading Sources for Android SDK, API 22, revision 1
  Installing Sources for Android SDK, API 22, revision 1
INFO   | jvm 5    | 2016/06/09 08:55:40 | 2016-06-09 08:55:40,053 INFO [0-BAM::0741f65689c0::Agent:pool-3-thread-1] [BuildAgentControllerImpl] Agent 1474561 checking build queue for executables...
    Installed Sources for Android SDK, API 22, revision 1
  Done. 1 package installed.

再度、ABIをインストールしてみる・・・

android update sdk -a --no-ui --filter sys-img-armeabi-v7a-android-22,sys-img-x86_64-android-22
Installing Archives:
  Preparing to install archives
  Skipping 'ARM EABI v7a System Image, Android API 22, revision 1'; it depends on 'SDK Platform Android 5.1.1, API 22, revision 2' which was not installed.
  Skipping 'Intel x86 Atom_64 System Image, Android API 22, revision 5'; it depends on 'SDK Platform Android 5.1.1, API 22, revision 2' which was not installed.
  Done. Nothing was installed.

sourceとandroidを勘違いした。

root@0741f65689c0:/home/android_program# android update sdk -a --no-ui --filter android-22
Installing Archives:
  Preparing to install archives
  Downloading SDK Platform Android 5.1.1, API 22, revision 2
  Installing SDK Platform Android 5.1.1, API 22, revision 2
    Installed SDK Platform Android 5.1.1, API 22, revision 296%)
  Done. 1 package installed.

ようやくABIのインストールに成功。

root@0741f65689c0:/home/android_program# android update sdk -a --no-ui --filter sys-img-armeabi-v7a-android-22,sys-img-x86_64-android-22
Installing Archives:
  Preparing to install archives
  Downloading ARM EABI v7a System Image, Android API 22, revision 1
  Installing ARM EABI v7a System Image, Android API 22, revision 1
    Installed ARM EABI v7a System Image, Android API 22, revision 199%)
  Downloading Intel x86 Atom_64 System Image, Android API 22, revision 5
  Installing Intel x86 Atom_64 System Image, Android API 22, revision 5
  Unzip failed: No space left on deviceage, Android API 22, revision 5 (5%)
  Done. 1 package installed.

AVDを作成しようとしたらディスクスペースが足りないとか。。
※後日補足:dockerはコンテナが使えるディスクスペースをデフォルトで10GB等に制限しているので、ディスクスペース問題はそれを変更すればよかっただけでした。

root@0741f65689c0:/home/android_program# android create avd --name myandroid22 -t "android-22" --abi "default/x86_64"
Android 5.1.1 is a basic Android platform.
Do you wish to create a custom hardware profile [no]n
Error: No space left on device
Error: AVD not created.

Android-SDK内の不要そうなファイルを手動で削除したら
今度は例外発生。
androidコマンドが全滅。。

root@0741f65689c0:~# android create avd --name myandroid22_02 -t "android-22" --abi "default/x86_64"
Exception in thread "main" java.lang.NullPointerException
    at java.io.File.<init>(File.java:277)
    at com.android.sdklib.internal.avd.AvdManager.parseAvdInfo(AvdManager.java:1623)
    at com.android.sdklib.internal.avd.AvdManager.buildAvdList(AvdManager.java:1584)
    at com.android.sdklib.internal.avd.AvdManager.<init>(AvdManager.java:357)
    at com.android.sdklib.internal.avd.AvdManager.getInstance(AvdManager.java:380)
    at com.android.sdkmanager.Main.getAvdManager(Main.java:295)
    at com.android.sdkmanager.Main.createAvd(Main.java:1252)
    at com.android.sdkmanager.Main.doAction(Main.java:337)
    at com.android.sdkmanager.Main.run(Main.java:151)
    at com.android.sdkmanager.Main.main(Main.java:117)

ダメだこれは。。

参考

http://stackoverflow.com/questions/10019532/no-abi-error-when-creating-an-android-virtual-device
http://www.javadrive.jp/android/emulator/index1.html
http://stackoverflow.com/questions/28921210/how-to-run-unit-tests-for-android-is-not-on-the-device-or-emulator

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