/home/tnishinaga/TechMEMO

日々行ったこと、面白かったことを書き留めます。

Arch LinuxのAndroid StudioでAndroidエミュレータが立ち上がらなかった件

数年ぶりに簡単なAndroidアプリを作ってみたくなったので、AndroidStudioをインストールしてとりあえずHelloWorldアプリを動かそうとしたのですが、AVDマネージャーからAndroidエミュレータの起動ボタンを押しても一向に端末の画面が出てきてくれる気配がありません。

今回はこの問題について、こうして原因特定して、調べて、動くようにしましたというメモです。

開発環境

OS Arch Linux(x86_64)
IDE AnrdoidStudio
AndroidSDKインストール ~/Android

問題

AVDマネージャーからAndroidエミュレータが起動しない。

原因特定

AndroidStudioのGUIから起動しようとすると何処にエラーログが出ているかわからなかったので、「たぶんCUIからもエミュレータの起動は可能で、CUIから起動すればエラーログも見えるでしょう」と考えてCUIで起動する方法を探しました。

CUIからのエミュレータ起動は、emulatorという実行バイナリを使って行えます。 これらはAndroidSDKのtoolsディレクトリ以下(こちらの環境では~/Android/Sdk/tools)にありました。

emulatorのhelpを見ると、AVDマネージャで作成したデバイス名を引数に渡すと良いようです。

$ ./emulator --help
emulator: ERROR: No AVD specified. Use '@foo' or '-avd foo' to launch a virtual device named 'foo'

AVDマネージャで作成したデバイス一覧は、tools/bin以下のavdmanagerにlist avdと指定すると教えてくれます。 私の環境で実行した結果は以下のような感じ。

 ./bin/avdmanager list avd
Available Android Virtual Devices:
Name: Nexus_S_API_25
Device: Nexus S (Google)
Path: /home/tnishinaga/.android/avd/Nexus_5X_API_25.avd
Target: Google APIs (Google Inc.)
Based on: Android 7.1.1 (Nougat) Tag/ABI: google_apis/x86
Skin: nexus_s
Sdcard: /home/tnishinaga/.android/avd/Nexus_5X_API_25.avd/sdcard.img

後はエミュレータを起動するだけです。

$ ./emulator -avd Nexus_S_API_25
sh: glxinfo: command not found
sh: glxinfo: command not found
emulator: ERROR: Failed to retrieve DNS servers list from the system
emulator: WARNING: Cannot find system DNS servers! Name resolution will be disabled.
emulator: WARNING: encryption is off
emulator: WARNING: UpdateCheck: Failure: Error
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libGL error: unable to load driver: i965_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: i965
libGL error: unable to load driver: i965_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: i965
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
X Error of failed request:  BadValue (integer parameter out of range for operation)
Major opcode of failed request:  156 (GLX)
Minor opcode of failed request:  24 (X_GLXCreateNewContext)
Value in failed request:  0x0
Serial number of failed request:  42
Current serial number in output stream:  43
QObject::~QObject: Timers cannot be stopped from another thread
Segmentation fault (core dumped)

エラーのようなのは以下の3つ:

  • sh: glxinfo: command not found
  • emulator: ERROR: Failed to retrieve DNS servers list from the system
  • X Error of failed request: BadValue (integer parameter out of range for operation)

glxinfoが無いと言われる件は、yaourtでAURからインストールすれば解決しますが、それでもエミュレータは起動しません。

DNSもどうのう言ってますが、それだけでエミュレータがセグフォするとは考えられないので無視します。

最後のX周りのエラーが怪しいです。

調査と解決

Xのところをエラー文でググると、それっぽいものがヒット。

stackoverflow.com

libstdc++のことが取り上げられてますが、X周りならGraphics系じゃないかなーと描画方法をAutomaticからSoftwareに変更したところ、動くようになりました。

解決方法

f:id:tnishinaga:20170504025017p:plain

Emulated PerformanceのGraphicsのところをSoftwareにする。

ベストな解決方法じゃないかもしれませんが、とりあえず動けば良いのでこれで開発を続けようと思います。

ベストな方法をご存じの方はコメントで教えていただけると嬉しいです。

以上。