Genymotion 無料版 を入れる 2018

ちょっとした検証をドトールでやるとき、実機を出すのは面倒。

かといって公式エミュレータはいまいち感。

なので、ひさびさに入れてみました Genymotion。


Genymotion Android Emulator | Cloud-based Android virtual devices | Develop - Automate your tests - Validate with confidence

 

個人利用の無料版

公式サイトの分かりづらいとこにしれっとある。

上部の「Help」から、

「Genymotion Desktop」-「Fun Zone」

で。

ライセンスキーは不要。アカウント作成→ログインのみで無料利用可能。

Genymotion For Fun – Free Android Emulator (For Personal Use)

 

VirtualBox

「自分でいれなさい」とリンク付きダイアログで言われた。

Downloads – Oracle VM VirtualBox

入れるだけ。

 

GApps を入れる。

【本当に32ビット?】Android端末の CPU の ABI を特定する

「x86」で入れる。

The Open GApps Project

デバイスのイメージを作成後、開いた画面の上にドラッグ&ドロップ。

 

まとめ

以前他で入れていた VirtualBox の残骸などは一度アンインストールしたほうがネットワーク設定などをしなくていいので楽。

あと、Virtual Box を開いたままで Genymotion にログインしようとすると、ネットワークエラーでできない。

いくつか、他のエミュレータを試したがこれが一番なのは今も?

→ Android Studio エミュレータのネットワーク設定

中華のがよい? ⇣

継続する 5555/TCP ポート宛攻撃通信と ADB が有効化された脆弱な Android エミュレータについて


AndroidManifest.xml に Admob application ID の記述が必須になったとさ

こんなエラーメッセージ。


E/AndroidRuntime: FATAL EXCEPTION: main
    Process: ru.balumates.balu, PID: 4409
    java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException:

    ******************************************************************************
    * The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
    * should follow the instructions here: https://goo.gl/fQ2neu to add a valid  *
    * App ID inside the AndroidManifest. Google Ad Manager publishers should     *
    * follow instructions here: https://goo.gl/h17b6x.                           *
    ******************************************************************************


        at android.app.ActivityThread.installProvider(ActivityThread.java:6242)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:5805)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5722)
        at android.app.ActivityThread.-wrap1(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: java.lang.IllegalStateException:

    ******************************************************************************
    * The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
    * should follow the instructions here: https://goo.gl/fQ2neu to add a valid  *
    * App ID inside the AndroidManifest. Google Ad Manager publishers should     *
    * follow instructions here: https://goo.gl/h17b6x.                           *
    ******************************************************************************


        at com.google.android.gms.internal.ads.zzmn.attachInfo(Unknown Source:17)
        at com.google.android.gms.ads.MobileAdsInitProvider.attachInfo(Unknown Source:3)
        at android.app.ActivityThread.installProvider(ActivityThread.java:6239)
        	... 10 more
Disconnected from the target VM, address: 'localhost:8600', transport: 'socket'

Google Mobile Ads SDK v17.0.0 以降で必須だと。

Google Ads Developer Blog: Announcing v17.0.0 of the Android Google Mobile Ads SDK

このことは、


implementation "com.google.firebase:firebase-ads:17.0.0"

も同じ。

以下、AndroidManifest.xml の必須記述。


<manifest>
  <application>
    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="ca-app-pub-################~##########"/>

  </application>
</manifest>

Ad Manager や NativeAppInstallAd / NativeContentAd も注意が必要な模様。


Kotlin 1.3 で CoroutineScope

Kotlin 1.3 RC is Here: Migrate Your Coroutines! | Kotlin Blog

新しくこんなの出てます。


public interface CoroutineScope {

  /**
   * Returns `true` when this coroutine is still active (has not completed and was not cancelled yet).
   *
   * Check this property in long-running computation loops to support cancellation:
   * ```
   * while (isActive) {
   *   // do some computation
   * }
   * ```
   *
   * This property is a shortcut for `coroutineContext.isActive` in the scope when
   * [CoroutineScope] is available.
   * See [coroutineContext][kotlin.coroutines.experimental.coroutineContext],
   * [isActive][kotlinx.coroutines.experimental.isActive] and [Job.isActive].
   *
   * @suppress **Deprecated**: Deprecated in favor of top-level extension property
   */
  @Deprecated(level = DeprecationLevel.HIDDEN, message = "Deprecated in favor of top-level extension property")
  public val isActive: Boolean
    get() = coroutineContext[Job]?.isActive ?: true

  /**
   * Returns the context of this scope.
   */
  public val coroutineContext: CoroutineContext

}

新しいコルーチンのスコープです。

すべてのコルーチンビルダーは CoroutineScope の拡張となり、これを継承したコルーチンコンテキストは自動的にすべての要素にキャンセルを伝えることができます。

これを使って、アクティビティのライフサイクル周りを実装します。


class MyActivity : AppCompatActivity(), CoroutineScope {

  lateinit var job: Job

  override val coroutineContext: CoroutineContext
      get() = Dispatchers.Main + job


  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    job = Job()
  }


  override fun onDestroy() {
    super.onDestroy()

    // すべての子ジョブが destroy されたあと
    // 自動的にキャンセル
    job.cancel() 
  }


  // Activity が destroy されるか、このメソッド内で、例外が
  // 発生すると、すべてのネストしたコルーチンはキャンセルされる

  fun loadDataFromUI() = launch { // メインスレッドで起動

    val ioData = async(Dispatchers.IO) { // IOコンテキストで起動
      // ブロッキング I/O 処理
    }

    //  I/O の結果を wait
    val data = ioData.await()

    // メインスレッドで描画
    draw(data) 
  }
}

簡単な記述で、ネストしたコルーチンすべてを自動的にキャンセルしてくれるのです。

Kotlin 1.3 RC is Here: Migrate Your Coroutines! | Kotlin Blog

Using Kotlin Coroutines in your Android App