【Flutter】Android実機にインストールする


1)

デバイスが認識されていることを確認。
認識されていなければこちらを実行します。 👉 https://qiita.com/nitaking/items/ec3191d3ca51980396bf

$ flutter devices

1 connected device:

ELE L29 (mobile) • XPH0219419007455 • android-arm64 • Android 10 (API 29)

2)

flutterプロジェクトに移動します。
プロジェクトルートで以下を実行してください。
今回はXPH0219419007455にインストールします。

 $ flutter install -d XPH0219419007455

Installing app.apk to AOSP on IA Emulator...
Uninstalling old version...
Installing build/app/outputs/flutter-apk/app.apk...                 4.4s

無事インストールできたら完了です!


インストールに失敗するとき

flutter-apk/app.apk: Failure [INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries, res=-113]

このようなエラーが出る場合、端末間のバイナリデータの違いによってエラーになります(ぼんやり理解なので詳しくはよりお調べください)
以下の用に設定すれば実機インストール可能です。

// android/build.gradle

android{
    ...
    defaultConfig{
        ...
        //Add this ndk block of code to your build.gradle
        ndk {
            abiFilters "x86", "arm64-v8a"
        }
    }
}

refs:
https://stackoverflow.com/a/57848743/8023331
https://github.com/flutter/flutter/issues/31579
https://qiita.com/mkosuke/items/afa40c09078285034799