Gappsのinstallが楽になったGenymotion 2.10

前回までのまとめ

exception-think.hatenablog.com

動作環境

  • macOS Sierra
  • 16G
  • HDDタイプのiMac
  • AS 3.0-Canary9
  • gradle plugin 2.3.3
  • gradle runtime-4.1-rc2-bin.zip

試食状況

今回はPlayerの改修のみですね。imageの更新は促されなかった

で、新規イメージから試してみたんですが

  • Gappsを入れる同意ダイアログが出る
  • OKを押すとinstall開始
  • 終了時にOpemGappsのサイトがブラウザで開く*1
    • これ余計な操作の気もするんだけど。謝辞的な意味合いなのかな?
  • イメージの再起動は手動でしてくださいの表示が出る
  • 手動で再起動するとGooglePlayが使えるようになる

QAテストツールみたいな立場でマネタイズを狙ってるみたいなので、エンジニアじゃない人向けの改修 なのかなーとは思う

でも 有料library とかは x86を用意していないのでクラッシュなパターンが多いわけなんだけどな・・*2


公式エミュの話

AndroidWear にpush通知がとばない という話があり調べていたんですけど、

実機は流石に会社にないんだよなー。

もちろん自分個人はもってますけど仕事場のNWにつなぐのは流石に躊躇されるわけで。

エミュレータがないと不便ということで試した状況

push通知的な話

  • NotificationCompat.WearableExtender あたりの対応が必要
  • バイブや音を鳴らさないとAndroid Wearへ直ぐに通知が届かない!! 下記辺り追記

.setVibrate(new long[]{0, 200, 100, 200, 100, 200})

 public static void notify(Context context, Intent intent, String title, String message, int id){
        int requestID = (int) System.currentTimeMillis();
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), requestID, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        //カラーアイコン、■アイコン対応はOS7から
        int icon = R.drawable.ic_notify;  //◎抜き有りの白黒アイコン
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            icon  = R.drawable.ic_main; //通常のアプリアイコン(四角い塗りつぶしカラーアイコンを想定)
        }


        // Wear 用 Action を作成
        NotificationCompat.Action action =
                new NotificationCompat.Action.Builder(R.drawable.android_notification,
                        title, pendingIntent)
                        .build();

        Bitmap largeIcon =BitmapFactory.decodeResource(
                context.getResources(), R.drawable.ic_main_large);
        NotificationCompat.WearableExtender wearableExtender =
                new NotificationCompat.WearableExtender()
                        .setContentIcon(R.drawable.android_notification) //カード内アイコン表示
                        .setContentIconGravity(GravityCompat.START)      //左側表示
                        .addAction(action) //Wear用ActionButton対応
                        .setBackground(largeIcon);


        //notificationの生成
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context.getApplicationContext())
                .setTicker(context.getString(R.string.app_name))// 通知バーに表示する簡易メッセージ
                .setContentTitle(context.getString(R.string.app_name))
                .setContentText(title)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(message))//これで複数行が表示される
                .setSmallIcon(icon)//表示するアイコン
                //.setLargeIcon(largeIcon) // Android Wear の通知カードの背景画像として表示される ★<= 表示が微妙になるのでやめる
                .setWhen(System.currentTimeMillis())//通知時間
                .setContentIntent(pendingIntent)//PendingIntentをセットする
                .setAutoCancel(true)//タップするとキャンセル(消える)
                .setOnlyAlertOnce(true) // この通知がまだ表示されていない場合は音やバイブレーション、ショートメッセージの表示を行う
                .setColor(ContextCompat.getColor(context.getApplicationContext(), R.color.colorAccent))
                .extend(wearableExtender) //Wear用設定の追記
                //.addAction(R.drawable.android_notification,title,pendingIntent) //ActionButton対応 ★<= ボタンが二重表示?されるのでやめる
                .setVibrate(new long[]{0, 200, 100, 200, 100, 200}) // 【注意】バイブや音を鳴らさないとAndroid Wearへ直ぐに通知が届かない!!
                ;

        //NotificationManagerを取得
        NotificationManagerCompat managerCompat = NotificationManagerCompat.from(context.getApplicationContext());
        managerCompat.notify(id, builder.build());
    }

ただ 25/26のWearエミュ どっちも作ってみましたが表示差分が大きいかなと

  • 25でちゃんと見えていても26だと表示が微妙だったり
  • ic_main アイコンが実機だと問題ないのに、wear26エミュ上 だと豆腐になるとか
    • 接続されているwearのSDK_INTってわからないしな・・。うーん。

genymotionとの共用状況

以前 genymotion x86Android Emurator(x86)の共用はできない でしたが

現在の時点では問題ないようです*3

下準備的な設定

Android Wearエミュレータ

  • Android Wearの emu image自体はAS上で作成
  • Android Wearの emu
    • Settings>About>Build number 7回タップ
    • Developer options>ADB debugging ON

ホスト側

実機でもgenymotionでもOK

  • Android Wearのアプリを入れておく
  • adb -s XXXX forward tcp:5601 tcp:5601 で接続 (-s XXXX はPhoneホスト側)
    • これはpecoでshellを作っておくと楽(ptcp.bat)  
  • ptcp.bat
@echo off

for /f %%j in ('adb devices -l ^|grep -v attached ^|grep -v daemon  ^| peco --select-1 ') do ( 
     echo device %%j
     adb -s %%j forward tcp:5601 tcp:5601
     break
)

f:id:kimukou_26:20170805091315p:plain

やりたいこと

  • 実際の挙動確認実行はコマンドラインでしたい

    • AS経由で起動するとエミュが死ぬタイミングで何故かIDEが死ぬようになったので・・
  • pw.sh

#!/bin/sh
DEVICE=`adb devices -l |grep -v attached |grep -v daemon | grep -v -e '^\s*#' -e '^\s*$'| peco --select-1 |awk '{print $1}'`

echo "DEVICE:"$DEVICE
echo "OS    :"`adb -s $DEVICE shell getprop ro.build.version.release`

adb -s $DEVICE forward tcp:5601 tcp:5601

adb forward用。実機だけなら adb -d でつなくという手もあるわけですが・・

  • pemu.sh
#!/bin/sh

# see http://qiita.com/tenmyo/items/f547806f128606ae22d3
#player=$HOME/Library/Android/sdk/tools/emulator  //<= こっちは動かないemurator
player="$HOME/Library/Android/sdk/emulator/emulator"

# see http://qiita.com/kgmyshin/items/9964b9cc2193d1cae985
option="-writable-system -netdelay none -netspeed full -noaudio -netfast -no-boot-anim -nojni -memory 768"
# -force-32bit


#name=`emulator -list-avds | peco --select-1`
# tools 25.3.0 以降は余分な空白を除去する必要あり
name=`emulator -list-avds | grep -v -e '^\s*#' -e '^\s*$' | peco --select-1`


echo "[PLAYER]"$player
echo "[OPTION]"$option
echo "[ BOOT ]"$name

$player -avd $name $option &

ASおまかせだと、macだと下記の位置に入るのですが

$HOME/Library/Android/sdk
    emulator
         emulator    //動く位置
    tools
         emurator    //動かない位置。cmpコマンドで比較すると同じバイナリっぽい

toolsによくpathを通してしまうと、toolsの方のemuratorの方参照して誤動作してしまうというアホなオチがあり・・。

emuratorのバイナリ自体は同じなんだけど、相対パスで見ているqmenuのライブラリの位置が見つからないエラー

$ emulator -help
Android Emulator usage: emulator [options] [-qemu args]
  options:
    -list-avds                     list available AVDs
    -sysdir <dir>                  search for system disk images in <dir>
    -system <file>                 read initial system image from <file>
    -writable-system               make system image writable after 'adb remount'
    -datadir <dir>                 write user data into <dir>
    -kernel <file>                 use specific emulated kernel
    -ramdisk <file>                ramdisk image (default <system>/ramdisk.img
    -image <file>                  obsolete, use -system <file> instead
    -initdata <file>               same as '-init-data <file>'
    -data <file>                   data image (default <datadir>/userdata-qemu.img
    -partition-size <size>         system/data partition size in MBs
    -cache <file>                  cache partition image (default is temporary file)
    -cache-size <size>             cache partition size in MBs
    -no-cache                      disable the cache partition
    -nocache                       same as -no-cache
    -sdcard <file>                 SD card image (default <datadir>/sdcard.img
    -snapstorage <file>            file that contains all state snapshots (default <datadir>/snapshots.img)
    -no-snapstorage                do not mount a snapshot storage file (this disables all snapshot functionality)
    -snapshot <name>               name of snapshot within storage file for auto-start and auto-save (default 'default-boot')
    -no-snapshot                   perform a full boot and do not do not auto-save, but qemu vmload and vmsave operate on snapstorage
    -no-snapshot-save              do not auto-save to snapshot on exit: abandon changed state
    -no-snapshot-load              do not auto-start from snapshot: perform a full boot
    -snapshot-list                 show a list of available snapshots
    -no-snapshot-update-time       do not do try to correct snapshot time on restore
    -wipe-data                     reset the user data image (copy it from initdata)
    -avd <name>                    use a specific android virtual device
    -skindir <dir>                 search skins in <dir> (default <system>/skins)
    -skin <name>                   select a given skin
    -no-skin                       deprecated: create an AVD with no skin instead
    -noskin                        same as -no-skin
    -memory <size>                 physical RAM size in MBs
    -accel <mode>                  Configure emulation acceleration
    -no-accel                      Same as '-accel off'
    -ranchu                        Use new emulator backend instead of the classic one
    -engine <engine>               Select engine. auto|classic|qemu2
    -netspeed <speed>              maximum network download/upload speeds
    -netdelay <delay>              network latency emulation
    -netfast                       disable network shaping
    -code-profile <name>           enable code profiling
    -show-kernel                   display kernel messages
    -shell                         enable root shell on current terminal
    -no-jni                        disable JNI checks in the Dalvik runtime
    -nojni                         same as -no-jni
    -logcat <tags>                 enable logcat output with given tags
    -no-audio                      disable audio support
    -noaudio                       same as -no-audio
    -audio <backend>               use specific audio backend
    -radio <device>                redirect radio modem interface to character device
    -port <port>                   TCP port that will be used for the console
    -ports <consoleport>,<adbport> TCP ports used for the console and adb bridge
    -onion <image>                 use overlay PNG image over screen
    -onion-alpha <%age>            specify onion-skin translucency
    -onion-rotation 0|1|2|3        specify onion-skin rotation
    -dpi-device <dpi>              specify device's resolution in dpi (default 165)
    -scale <scale>                 scale emulator window (deprecated)
    -http-proxy <proxy>            make TCP connections through a HTTP/HTTPS proxy
    -timezone <timezone>           use this timezone instead of the host's default
    -dns-server <servers>          use this DNS server(s) in the emulated system
    -cpu-delay <cpudelay>          throttle CPU emulation
    -no-boot-anim                  disable animation for faster boot
    -no-window                     disable graphical window display
    -version                       display emulator version number
    -report-console <socket>       report console port to remote socket
    -gps <device>                  redirect NMEA GPS to character device
    -shell-serial <device>         specific character device for root shell
    -tcpdump <file>                capture network packets to file
    -bootchart <timeout>           enable bootcharting
    -charmap <file>                use specific key character map
    -prop <name>=<value>           set system property on boot
    -shared-net-id <number>        join the shared network, using IP address 10.1.2.<number>
    -nand-limits <nlimits>         enforce NAND/Flash read/write thresholds
    -gpu <mode>                    set hardware OpenGLES emulation mode
    -camera-back <mode>            set emulation mode for a camera facing back
    -camera-front <mode>           set emulation mode for a camera facing front
    -webcam-list                   lists web cameras available for emulation
    -screen <mode>                 set emulated screen mode
    -force-32bit                   always use 32-bit emulator
    -selinux <disabled|permissive> Set SELinux to either disabled or permissive mode
    -unix-pipe <path>              Add <path> to the list of allowed Unix pipes
    -fixed-scale                   Use fixed 1:1 scale for the initial emulator window.
    -wait-for-debugger             Pause on launch and wait for a debugger process to attach before resuming
    -skip-adb-auth                 Skip adb authentication dialogue

     -qemu args...                 pass arguments to qemu
     -qemu -h                      display qemu help

     -verbose                      same as '-debug-init'
     -debug <tags>                 enable/disable debug messages
     -debug-<tag>                  enable specific debug messages
     -debug-no-<tag>               disable specific debug messages

     -help                         print this help
     -help-<option>                print option-specific help

     -help-disk-images             about disk images
     -help-debug-tags              debug tags for -debug <tags>
     -help-char-devices            character <device> specification
     -help-environment             environment variables
     -help-virtual-device          virtual device management
     -help-sdk-images              about disk images when using the SDK
     -help-build-images            about disk images when building Android
     -help-all                     prints all help content

2017/10 追記(win版対応)

なんか下記な変な環境のお仕事をすることに陥ってるのでbat版書いてみる

  • Win環境でプロパーさんしか専用のノートPCで実機が繋げない*4
  • 一般開発者はカスタムしたemuのみ*5

遅延環境変数の話は下記参照

  • pemu.bat
@echo off
setlocal enabledelayedexpansion  //<=遅延環境変数を使うためのおまじない

rem see http://qiita.com/tenmyo/items/f547806f128606ae22d3
rem set player=C:/Android/sdk/tools/emulator  //<= こっちは動かないemurator
set player=C:/Android/sdk/emulator/emulator

rem  see http://qiita.com/kgmyshin/items/9964b9cc2193d1cae985
set option=-writable-system -netdelay none -netspeed full -noaudio -netfast -no-boot-anim -nojni -memory 768
rem -force-32bit


rem tools 25.3.0 以降は余分な空白を除去する必要あり
for /f %%i in ('emulator -list-avds ^| grep -v -e '^\s*#' -e '^\s*$' ^| peco --select-1') do (
  set name = %%i 
  rem if/for文内部の set文は遅延化のため、%A%で参照できないので !A!でアクセスする
  echo boot !name!

  echo "[PLAYER]"%player%
  echo "[OPTION]"%option%
  echo "[ BOOT ]"!name!

  start /b %player% -avd !name! %option%
  break
)

winでgrepを使う話は下記を参照

exception-think.hatenablog.com

*1:ここから落としましたよ的な

*2:一部のNativeAdとかも含む

*3:x86のHAXM runtimeとVBOXの動作がぶつかってた emuratorと別物が別途導入されている

*4:ISMSのセキュリティ施策のため

*5:imgとskinをカスタムしているため最新のものを上書き利用