Issue 1:
Summary

Basically, if you have multiple users on an android phone, flutter deploys sometimes to the wrong user account. Unless you switch accounts, this looks like the deploy totally failed.

Steps to Reproduce

Setup an Android phone with multiple accounts

Build a flutter app

do a "flutter run"

flutter seems to hang, nothing happens (if actually used user has not logged in yet) or flutter seems to run but no app appears on phone (because it gets installed to an other account)

When checking the App via "Settings/memory/other apps" it sometimes says "not available for user".

Used hardware

BQ Aquaris X with Android 8.1.

Output from flutter doctor -v

Flutter (Channel beta, v0.11.3, on Microsoft Windows [Version 10.0.17134.345], locale de-DE)
• Flutter version 0.11.3 at C:\tools\flutter
• Framework revision 72bf075e8d (4 days ago), 2018-11-09 20:36:17 -0800
• Engine revision 5646e86a6f
• Dart version 2.1.0 (build 2.1.0-dev.9.3 9c07fb64c4)

[!] Android toolchain - develop for Android devices (Android SDK 28.0.3)
• Android SDK at C:\Users\Oliver\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
X Android license status unknown.

[√] Android Studio (version 3.2)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 30.0.1
• Dart plugin version 181.5656
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[√] IntelliJ IDEA Community Edition (version 2018.2)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.2
• Flutter plugin version 29.1.2
• Dart plugin version 182.3569.4

[!] VS Code (version 1.28.2)
• VS Code at C:\Users\Oliver\AppData\Local\Programs\Microsoft VS Code
• Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (1 available)
• Aquaris X • BJ106805 • android-arm64 • Android 8.1.0 (API 27)

Logs and explanation

from flutter run --verbose:
"executing: C:\Users\Oliver\AppData\Local\Android\sdk\platform-tools\adb -s BJ106805 shell am start -a
android.intent.action.RUN -f 0x20000000 --ez enable-background-compilation true --ez enable-dart-profiling true
klages.de.bla/klages.de.bla.MainActivity"

This is missing the --user parameter. From the ADB manual:

"--user user_id | current: Specify which user to run as; if not specified, then run as the current user."

"then run as current user " either doesn't work or the definition of current user is not what i would expect :-)

Issue 2:
Internal: b/142944798

flutter run cannot pass --user flag to adb launcher.

flutter/packages/flutter_tools/lib/src/android/android_device.dart

Lines 414 to 420
in
8dd06a1

cmd = adbCommandForDevice(<String>[

'shell', 'am', 'start',

'-a', 'android.intent.action.RUN',

'-f', '0x20000000', // FLAG_ACTIVITY_SINGLE_TOP

'--ez', 'enable-background-compilation', 'true',

'--ez', 'enable-dart-profiling', 'true',

]);

That means users can't select to launch their apps in work profile vs personal profile. This is critical for any enterprise app that needs to be tested in this mode.

See work profile section in https://developer.android.com/studio/run/.