Skip to content

Conversation

@jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Apr 3, 2021

Allow flutter run to work end to end with a UWP device.

Uses win32/ffi for the actual launch of the application, injected via the native API class. This is structured to avoid a g3 dependency.

Install and amuid require powershell scripts for now.

Actually connecting to the observatory requires running a command in an elevated prompt. Instructions are presented to the user if a terminal is attached.

@flutter-dashboard flutter-dashboard bot added c: contributor-productivity Team-specific productivity, code health, technical debt. tool Affects the "flutter" command-line tool. See also t: labels. labels Apr 3, 2021
@google-cla google-cla bot added the cla: yes label Apr 3, 2021
@clarkezone
Copy link

For the path: build\winuwp\runner_uwp\AppPackages\helloreloaded\helloreloaded_1.1.3.0_x64_Debug_Test

  • build\winuwp\runner_uwp\AppPackages is a constant
  • helloreloaded is a value in the manifest that will ultimately by injected by the flutter tool
  • the next dir is a concat of
    • helloreloaded the same as the injected app name
    • 1.1.0.0 comes from the manifest
    • _x64_Debug_Test should correspond to the build arguments passed to / by cmake and should be the same for any project for release and debug

cli_util: 0.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
clock: 1.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
csslib: 0.17.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
devtools: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay!

@jonahwilliams jonahwilliams marked this pull request as ready for review April 28, 2021 16:33
@jonahwilliams jonahwilliams requested a review from Piinks as a code owner April 28, 2021 16:33
useSseForDebugProxy: useSseForDebugProxy,
useSseForDebugBackend: useSseForDebugBackend,
useSseForInjectedClient: useSseForInjectedClient,
serveDevTools: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was required to roll in dwds, was the fix for the removal of the devtools dep I landed to resolve the version conflict post mortem

@zanderso
Copy link
Member

Is it possible to stage the package updates before this PR so they can be tested separately on CI?

@jonahwilliams
Copy link
Contributor Author

Done here: #81403

Copy link

@clarkezone clarkezone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jonahwilliams jonahwilliams changed the title [flutter_tools] add scaffolding for winuwp native launch [flutter_tools] support flutter run -d winuwp Apr 28, 2021
if (!cmakeFile.existsSync()) {
return null;
}
final RegExp nameSetPattern = RegExp(r'^\s*set\(PACKAGE_GUID\s*"(.*)"\s*\)\s*$');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this regexp have test coverage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

throw WindowsException(hResult);
}
final int id = processId.value;
free(aumid);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

free() calls should go in a finally {} block, for example to cover the exception thrown on line 30.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

free(processId);
free(aam.ptr);
free(arguments);
CoUninitialize();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I'm guessing this as well would have to go in the finally {} ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

_nativeApi = nativeApi,
_operatingSystemUtils = operatingSystemUtils,
_fileSystem = fileSystem,
super(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the indentation right here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const Win32NativeApi();

@override
int launchApp(String amuid, List<String> args) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clarkezone @cbracken Was an alternative design considered in which we would get this functionality from a utility bundled with the Windows engine artifacts instead of adding the ffi dependencies to the flutter_tool? For example, the Windows engine artifacts could come with a program, like uwp_launcher that does what is in this file, and then the flutter_tool could launch a uwp app using dart:io as usual through that launcher program?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having an adb like program for UWP would be pretty neat. I have to add that I'm indifferent between that and using ffi, but prefer both to calling out to powershell scripts. The former could give reasonable exit codes with meaning, the latter is just sort of a jumbled mess of text

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even something less ambitious than adb might be easier to maintain and test than introducing dart:ffi to the tool for the first time. I would like to hear thoughts from @clarkezone and @cbracken on this before we land this PR because I suspect if this is landed as-is we won't take the opportunity to consider this again.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have strong opinion either way, although in the short term getting a E2E working solution is a high priority so I would prefer to get to that and improve / refactor later than do a big refactor now.

@jonahwilliams
Copy link
Contributor Author

Fixed the issues with the install path @clarkezone , but hit another error.

PS C:\Users\Jonah\Documents\flutter-uwp-template\src> C:\Users\Jonah\Documents\flutter-uwp-template\src\build\winuwp\runner_uwp\AppPackages\helloreloaded\helloreloaded_1.1.0.0_Debug_Test\Add-AppDevPackage.ps1
Found bundle: C:\Users\Jonah\Documents\flutter-uwp-template\src\build\winuwp\runner_uwp\AppPackages\helloreloaded\helloreloaded_1.1.0.0_Debug_Test\helloreloaded_1.1.0.0_x64_Debug.msixbundle

Installing app...
Found dependency package(s):
C:\Users\Jonah\Documents\flutter-uwp-template\src\build\winuwp\runner_uwp\AppPackages\helloreloaded\helloreloaded_1.1.0.0_Debug_Test\Dependencies\x86\Microsoft.VCLibs.x86.Debug.14.00.appx
C:\Users\Jonah\Documents\flutter-uwp-template\src\build\winuwp\runner_uwp\AppPackages\helloreloaded\helloreloaded_1.1.0.0_Debug_Test\Dependencies\x64\Microsoft.VCLibs.x64.Debug.14.00.appx

Add-AppxPackage: C:\Users\Jonah\Documents\flutter-uwp-template\src\build\winuwp\runner_uwp\AppPackages\helloreloaded\helloreloaded_1.1.0.0_Debug_Test\Add-AppDevPackage.ps1:444
Line |
 444 |              Add-AppxPackage -Path $DeveloperPackagePath.FullName -Dep …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Specified cast is not valid.

Error: Could not install the app.

I'm assuming this script requires some additional arguments?

@clarkezone
Copy link

clarkezone commented Apr 29, 2021

Hmm that's weird.. I'm not needing to provide extra arguments from the cmdline. What happens if you powershell .\add-appdevpackage.ps1 from a cmd prompt?

@jonahwilliams
Copy link
Contributor Author

Oh duh, my b

@jonahwilliams
Copy link
Contributor Author

The actual error is:

Add-AppxPackage : Deployment failed with HRESULT: 0x80073CFB, The provided package is already installed, and
reinstallation of the package was blocked. Check the AppXDeployment-Server event log for details.

Deployment of package F941A77F-8AE1-4E3E-9611-68FBD3C62AE8_1.1.0.0_x64__d7c8pgvss6ysm was blocked because the provided
package has the same identity as an already-installed package but the contents are different. Increment the version
number of the package to be installed, or remove the old package for every user on the system before installing this
package.

NOTE: For additional information, look for [ActivityId] fa72d8bc-327e-0000-e31c-d1fa7e32d701 in the Event Log or use
the command line Get-AppPackageLog -ActivityID fa72d8bc-327e-0000-e31c-d1fa7e32d701

At C:\Users\Jonah\Documents\flutter-uwp-template\src\build\winuwp\runner_uwp\AppPackages\helloreloaded\helloreloaded_1.
1.0.0_Debug_Test\Add-AppDevPackage.ps1:444 char:13
+             Add-AppxPackage -Path $DeveloperPackagePath.FullName -Dep ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceExists: (C:\Users\Jonah\...ebug.msixbundle:String) [Add-AppxPackage], PSInvalidO
   perationException
    + FullyQualifiedErrorId : DeploymentError,Microsoft.Windows.Appx.PackageManager.Commands.AddAppxPackageCommand

Error: Could not install the app.

@clarkezone
Copy link

Try going to start menu and uninstalling the app manually

@jonahwilliams
Copy link
Contributor Author

The problem is that the Add App package script does not install in dev mode by default, need to call install.ps1 which is in the same folder

@clarkezone
Copy link

Does that fix it?

@jonahwilliams
Copy link
Contributor Author

Seems to work consistently. Unfortunately on ToT the app isn't actually starting for me, I just a blank blue screen

@jonahwilliams
Copy link
Contributor Author

OK, problem was the old that was installed correctly was never getting uninstalled

@clarkezone
Copy link

#70211

@jonahwilliams jonahwilliams marked this pull request as draft May 11, 2021 21:49
cbracken added a commit to cbracken/flutter that referenced this pull request May 12, 2021
Allow flutter run to work end to end with a UWP device.

Uses win32/ffi for the actual launch of the application, injected via
the native API class. This is structured to avoid a g3 dependency.

Install and amuid require powershell scripts for now.

Actually connecting to the observatory requires running a command in an
elevated prompt. Instructions are presented to the user if a terminal is
attached.

This is a rebased version of
flutter#79684 by @jonahwilliams.
cbracken added a commit that referenced this pull request May 13, 2021
Allow flutter run to work end-to-end with a UWP device.

Uses win32/ffi for the actual launch of the application, injected via
the native API class. This is structured to avoid a g3 dependency.

Install and amuid require powershell scripts for now.

Actually connecting to the observatory requires running a command in an
elevated prompt. Instructions are presented to the user if a terminal is
attached.

This is a rebased version of #79684
by @jonahwilliams, updated to remove `NativeApi` and replace is with calls
to `uwptool`.

Part of #82085
@jonahwilliams
Copy link
Contributor Author

Superseded by #82373

@jonahwilliams jonahwilliams deleted the checking_win32 branch May 13, 2021 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: contributor-productivity Team-specific productivity, code health, technical debt. tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants