Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter: Debug Run with Android Device #237

Open
2 tasks done
hhstore opened this issue Nov 19, 2020 · 6 comments
Open
2 tasks done

Flutter: Debug Run with Android Device #237

hhstore opened this issue Nov 19, 2020 · 6 comments

Comments

@hhstore
Copy link
Owner

hhstore commented Nov 19, 2020

related:

@hhstore
Copy link
Owner Author

hhstore commented Nov 19, 2020

flutter 连接真实设备调试:

flutter 连接真机调试体验:

  • 解决下面的狗屎问题, 成功连接 Android 手机(小米 k30 Pro/16G 内存).
  • 虽然是在 debug 模式编译的 apk 包. 实际体验已经很流畅.(release 模式编译, apk 性能更好)
  • 页面切换, 动画/布局/都很正常. 获取系统权限也都正常.
  • 总体, 对 flutter 的性能, 很满意.

踩坑:

  • 真机连接, 自然是不可能顺利连上的.
  • 坑1: Android 编译报错.
  • 坑2: 小米k30 pro, 开发者选项设置参数.
  • 吐槽一下, 首次编译Android 到手机. 260s fuck! ! ! 下面截图有.

关于模拟器对比:

  • 综述: 请不要使用 Android 模拟器, 狗屎一样. 请使用 iOS 模拟器开发调试.
  • 综述: 请不要使用 Android 模拟器, 狗屎一样. 请使用 iOS 模拟器开发调试.
  • 综述: 请不要使用 Android 模拟器, 狗屎一样. 请使用 iOS 模拟器开发调试.
  • iOS 模拟器, 我开3个一起用, 都不会拖慢系统.
  • Android 模拟器打开后, mac 机器(16G 内存)会变得非常卡. bullshit.
  • flutter 编译到 iOS 模拟器, 非常快, 体验极佳.
  • 反之, 编译到 Android 模拟器, 慢如狗. 几十倍的等待时间.

ref:

@hhstore
Copy link
Owner Author

hhstore commented Nov 19, 2020

1. flutter 连接 Android 手机调试开发教程:

  • Android Phone: 小米 k30 pro 手机
  • Android 模拟器, 体验极差, 比 iOS 模拟器差一百倍. 狗屎一样.
  • 需要验证手机权限获取功能. so, 只好找个真机测试一下.

1.1 手机设置:

  • 打开开发者模式.
  • 手机 通过 Type-c 数据线, 连接 mac
  • 手机: 连接选项 -> USB 文件传输模式

踩坑: 注意 iMac 使用 USB-C 连接 Android 手机, 注意一定要等手机弹出连接选项 -> USB 文件传输模式. 才是正常.
这样 flutter device, 才能找到 Android 手机设备.
数据线, 要支持数据传输, 不能只是充电线.

小米手机可能遇到 apk 安装失败:

1.2 Mac 设置:

  • 执行运行命令, 可以看到设备列表, 默认第一个是手机. 其他是模拟器.

-> % flutter run
Multiple devices found:
Redmi K30 Pro (mobile) • b6da3c35                             • android-arm64 • Android 10 (API 29)
iPhone 8 (mobile)      • EF2FA701-7500-48CD-844D-00053D3466A0 • ios           • com.apple.CoreSimulator.SimRuntime.iOS-13-4 (simulator)
iPhone 11 (mobile)     • AC61ACFD-E743-4CF0-8DE4-9C822A9C1ECF • ios           • com.apple.CoreSimulator.SimRuntime.iOS-13-4 (simulator)
iPhone 11 Pro (mobile) • F467BF0B-3899-4FF5-81C0-3A9BA90C3993 • ios           • com.apple.CoreSimulator.SimRuntime.iOS-13-4 (simulator)
[0]: Redmi K30 Pro (b6da3c35)
[1]: iPhone 8 (EF2FA701-7500-48CD-844D-00053D3466A0)
[2]: iPhone 11 (AC61ACFD-E743-4CF0-8DE4-9C822A9C1ECF)
[3]: iPhone 11 Pro (F467BF0B-3899-4FF5-81C0-3A9BA90C3993)
Please choose one (To quit, press "q/Q"): 0
Launching lib/main.dart on Redmi K30 Pro in debug mode...
Running Gradle task 'assembleDebug'...


  • 解决下面FAQ 列举的问题, 成功连接到手机.

image

  • 手机正常打开测试 app.

image

1.3 FAQ:

  • 可能遇到的狗屎报错.

1.3.1 path_provider 报错:

image

  • 我是把 path_provider 相关包删除. 然后执行 clean, 再执行 run 运行.

# 重新拉包:
flutter pub get

# 删除 build 历史:
flutter clean

# 重新启动:
flutter run

1.3.2 小米手机开发者选项 - 大坑:

  • 解决上面问题后, 编译 apk 成功, 但是执行安装到手机. 出错.

image

Running Gradle task 'assembleDebug'... Done                        10.0s
✓ Built build/app/outputs/flutter-apk/app-debug.apk.
Installing build/app/outputs/flutter-apk/app.apk...                14.0s
Error: ADB exited with exit code 1
Performing Streamed Install

adb: failed to install /Users/henry/Documents/iSpace/hh/flutter-starter/build/app/outputs/flutter-apk/app.apk: Failure
[INSTALL_FAILED_USER_RESTRICTED: Install canceled by user]
Error launching application on Redmi K30 Pro.

  • 关键信息: [INSTALL_FAILED_USER_RESTRICTED: Install canceled by user]
  • 这个报错, 很迷惑性. 说是安装被用户取消. 实际上, 用户并没有看到任何提示.
  • 只有关闭下面这个选型, 才会有 apk 安装提示. (大坑)

-[x] 需要关闭选项: 高风险功能开启提醒. (这一项, 是开发者选项的最后一项) fuck.

image

@hhstore
Copy link
Owner Author

hhstore commented Nov 19, 2020

flutter 打包发布:

Android 发布:

iOS 发布:

@hhstore
Copy link
Owner Author

hhstore commented Nov 19, 2020

1

@hhstore hhstore changed the title Flutter: debug run with real device Flutter: debug run with real Android device Mar 29, 2021
@hhstore hhstore changed the title Flutter: debug run with real Android device Flutter: Debug Run with real Android Device Mar 29, 2021
@hhstore hhstore changed the title Flutter: Debug Run with real Android Device Flutter: Debug Run with Android Device Mar 29, 2021
@hhstore
Copy link
Owner Author

hhstore commented May 12, 2021

Android Studio 编译 原生项目:

  • 与 flutter 项目, 略有差异.

  • 当然, 只能连 Android 手机.

  • 示例项目: https://github.com/AlphaWallet/alpha-wallet-android

  • 以此项目为例子:

  • 点击 IDE 的 编译按钮, 编译通过, 手机上, 会弹出安装 app 提示. 然后允许安装.

  • 之后在 终端, 看 log.

image

@hhstore
Copy link
Owner Author

hhstore commented Aug 3, 2021

flutter release 发布包:

Android:


# 打 fat 包, 混合各 arm 版本的 API. 包体积大.
flutter build apk

# 分版本打包, 包体积变小
flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant