- Haven’s Developer Life
- My diary-ish tech blog
- Install Flutter on Linux
- Build and release a Linux app to the Snap Store
- Prerequisites
- Set up the build environment
- Install snapcraft
- Install Multipass
- Install LXD
- Overview of snapcraft
- Flutter snapcraft.yaml example
- Metadata
- Grade, confinement, and base
- Parts
- Desktop file and icon
- Flutter super-cool-app.desktop example
- Build the snap
- Publish
- Snap Store channels
- Snap Store automatic review
- Additional resources
- Desktop support for Flutter
- Beta Snapshot in stable channel
- Requirements
- Additional Windows requirements
- Additional macOS requirements
- Additional Linux requirements
- Create a new project
- Set up
- Create and run
- Using an IDE
- From the command line
- Windows UWP
- Build a release app
- Distribution
- Windows
- MSIX packaging
- Building your own zip file for Windows
- macOS
- Linux
- Add desktop support to an existing Flutter app
- macOS-specific support
- Entitlements and the App Sandbox
- Setting up entitlements
- Hardened Runtime
- Plugin support
- Using a plugin
- Writing a plugin
- Samples and codelabs
Haven’s Developer Life
My diary-ish tech blog
Install Flutter on Linux
On this post, I will demonstrate how to install flutter on Ubuntu distribution flawlessly + android SDK installation.
Well, I just tried to follow the description on Flutter docs but didn’t work for me 🙁 after spending some hours, finally got it work on my Elementary OS. So wanna share it as keeping it as my self-note.
Before get started, if you like intelliJ and very okay with android studio, just installing Android studio would be much of time saver. Because I manually installed Android SDK to make flutter app on VSCode without ginormous Android studio.
1) Clone Flutter repository
2) Move flutter repo to wherever you want Since I usually put my programs into ‘/usr/local/bin’, I’ll try that.
FYI, If your user account have no authority to /usr/local/bin, try this
It will change /usr/local directory’s owner to your user account & user group. If you know about File Permission, just modify that script, because I assume that’s just basic account which has group of same name.
3) Add flutter into environment PATH
If you want it to keep on forever, put the line under bottom of your .zshrc or .bashrc.
4) Run flutter to download dart SDK automatically.
After dart download, try
It will yell at you that you don’t have android toolchain or Android SDK.
5) Install Android SDK — 1. Install Java
You can try to install default-jdk. But on my case, I had to revert the version to 8.
6) Install Android SDK — 2. Install Android SDK
Go to Android Developer download, donwload sdk-tools-linux.zip and unzip it.
7) Install Android SDK — 3. Add to PATH
Move Android SDK folder to desired location and add to PATH also.
8) Install Android SDK — 4. Make repositories.cfg file
It will be needed to run sdkmanager and install libraries.
9) Install Android SDK — 5. Install packages
list command will show you which tools you can install. To run flutter, you need to install latest sdk version. SDK 28 is latest on this post so command will be
10) Install Android SDK — 5.1. If you got error to run sdkmanager
If your sdkmanager got error while running on commands, try this
Open sdkmanager with vim or nano.
Next, find DEFAULT_JVM_OPTS variable and add this line at the end of the line. Be careful with small quote.
And try running sdkmanager command again.
If you are going to make Android emulator either, do the same step on “avdmanager”.
11) Android licenses accept
Read the licenses and type “y”.
Additional) Create AVD on linux using avdmanager
I’m just writing this because I left my android in my home…:( But I really recommend to use Android studio if you need avd. Quick and easy.
First, install some more packages for avdmanager
Then run license again to agree with Terms of Use.
Now we are ready to create avd! Please check parameter list on docs for details
To run avd, use emulator. See more details on docs also
You might need to run as sudo for kvm.
Well if you just install android studio, you don’t have to worry about most of the steps I posted. But if you did same what I did (I had to set my Elementary OS size to 128GB while giving 300GB to my Windows…) and just want to use Visual Studio code as flutter development, it worth to try.
Источник
Build and release a Linux app to the Snap Store
During a typical development cycle, you test an app using flutter run at the command line, or by using the Run and Debug options in your IDE. By default, Flutter builds a debug version of your app.
When you’re ready to prepare a release version of your app, for example to publish to the Snap Store, this page can help.
Warning: Work in progress! This page covers desktop support for Linux, which is available as an alpha-quality feature in the Flutter dev channel. There are still notable feature gaps, including accessibility support. We strongly recommend that you examine the Desktop shells page in the Flutter wiki to understand known limitations and ongoing work.
Prerequisites
To build and publish to the Snap Store, you need the following components:
Set up the build environment
Use the following instructions to set up your build environment.
Install snapcraft
At the command line, run the following:
Install Multipass
Also at the command line, run the following:
To work correctly, Multipass requires access to the CPU virtualization extensions. If the extensions are not available for your CPU architecture, not enabled in BIOS, or not accessible (for instance if you are running a virtual machine without nested virtualization), you won’t be able to use Multipass.
If you see the following error, you should use LXD:
Install LXD
To install LXD, use the following command:
LXD can be used as an alternative backend during the snap build process. Once installed, LXD needs to be configured for use. The default answers are suitable for most use cases.
On the first run, LXD may not be able to connect to its socket:
This means you need to add your user name to the LXD (lxd) group, so log out of your session and then log back in:
Overview of snapcraft
The snapcraft tool builds snaps based on the instructions listed in a snapcraft.yaml file. To get a basic understanding of snapcraft and its core concepts, take a look at the Snap documentation and the Introduction to snapcraft. Additional links and information are listed at the bottom of this page.
Flutter snapcraft.yaml example
Place the YAML file in your Flutter project under
/snap/snapcraft.yaml . (And remember that YAML files are sensitive to white space!) For example:
The following sections explain the various pieces of the YAML file.
Metadata
This section of the snapcraft.yaml file defines and describes the application. The snap version is derived (adopted) from the build section.
Grade, confinement, and base
This section defines how the snap is built.
This section defines the application(s) that exist inside the snap. There can be one or more applications per snap. This example has a single application—super_cool_app.
The flutter-master extension sets your flutter channel to master . If you would like to build your app with the dev channel simply use the flutter-dev extension.
Plugs A list of one or more plugs for system interfaces. These are required to provide necessary functionality when snaps are strictly confined. This Flutter snap needs access to the network. DBus interface The DBus interface provides a way for snaps to communicate over DBus. The snap providing the DBus service declares a slot with the well-known DBus name and which bus it uses. Snaps wanting to communicate with the providing snap’s service declare a plug for the providing snap. Note that a snap declaration is needed for your snap to be delivered via the snap store and claim this well-known DBus name (simply upload the snap to the store and request a manual review and a reviewer will take a look).
When a providing snap is installed, snapd will generate security policy that will allow it to listen on the well-known DBus name on the specified bus. If the system bus is specified, snapd will also generate DBus bus policy that allows ‘root’ to own the name and any user to communicate with the service. Non-snap processes are allowed to communicate with the providing snap following traditional permissions checks. Other (consuming) snaps may only communicate with the providing snap by connecting the snaps’ interface.
Parts
This section defines the sources required to assemble the snap.
Parts can be downloaded and built automatically using plugins. Similar to extensions, snapcraft can use various plugins (like Python, C, Java, Ruby, etc) to assist in the building process. Snapcraft also has some special plugins.
nil plugin Performs no action and the actual build process is handled using a manual override. flutter plugin Provides the necessary Flutter SDK tools so you can use it without having to manually download and set up the build tools.
Desktop file and icon
Desktop entry files are used to add an application to the desktop menu. These files specify the name and icon of your application, the categories it belongs to, related search keywords and more. These files have the extension .desktop and follow the XDG Desktop Entry Specification version 1.1.
Flutter super-cool-app.desktop example
Place the .desktop file in your Flutter project under
Notice: icon and .desktop file name must be the same as your app name in yaml file!
Place your icon with .png extension in your Flutter project under
Build the snap
Once the snapcraft.yaml file is complete, run snapcraft as follows from the root directory of the project.
To use the Multipass VM backend:
To use the LXD container backend:
Publish
Once the snap is built, you’ll have a .snap file in your root project directory. You can now publish the snap. The process consists of the following:
- Create a developer account at snapcraft.io, if you haven’t already done so.
- Register the app’s name. Registration can be done either using the Snap Store Web UI portal, or from the command line, as follows:
Snap Store channels
The Snap Store uses channels to differentiate among different versions of snaps.
The snapcraft upload command uploads the snap file to the store. However, before you run this command, you need to learn about the different release channels. Each channel consists of three components:
Track All snaps must have a default track called latest. This is the implied track unless specified otherwise. Risk Defines the readiness of the application. The risk levels used in the snap store are: stable , candidate , beta , and edge . Branch Allows creation of short-lived snap sequences to test bug-fixes.
Snap Store automatic review
The Snap Store runs several automated checks against your snap. There may also be a manual review, depending on how the snap was built, and if there are any specific security concerns. If the checks pass without errors, the snap becomes available in the store.
Additional resources
You can learn more from the following links on the snapcraft.io site:
Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the BSD License.
Источник
Desktop support for Flutter
Desktop support allows you to compile Flutter source code to a native Windows, macOS, or Linux desktop app. Flutter’s desktop support also extends to plugins—you can install existing plugins that support the Windows, macOS, or Linux platforms, or you can create your own.
Warning: Beta! This page covers desktop support, which is available as a beta release for Windows (Win32), macOS and Linux. The Windows UWP support is available as an alpha release. Beta support still has notable feature gaps, including accessibility support. Meanwhile, the Windows UWP alpha release is still in very active development. You can try a beta snapshot of desktop support on the stable channel, or you can keep up with the latest changes to desktop on the beta channel. For Windows UWP you need to be on the dev channel.
For more information, see the Desktop section in What’s new in Flutter 2, a free article on Medium.
Note: To compile a desktop application, you must build it on the targeted platform: build a Windows application on Windows, a macOS application on macOS, and a Linux application on Linux. If you experience a problem that hasn’t yet been reported, please file an issue and include “desktop:windows (win32)/windows (uwp)/macos/linux” (whichever platform is appropriate) in the title.
Beta Snapshot in stable channel
To make it easier to try out desktop support for Flutter, we are shipping a snapshot of Flutter’s desktop beta on the stable channel. This means that you can easily try desktop support without needing to switch to the Flutter beta channel. However, the snapshot included in the stable channel won’t be updated until the next Flutter stable release. If you want the latest version of desktop support, you must switch to the Flutter beta channel.
Requirements
To create a Flutter application with desktop support, you need the following software:
- Flutter SDK. See the Flutter SDK installation instructions.
- Optional: An IDE that supports Flutter. You can install Android Studio, IntelliJ IDEA, or Visual Studio Code and install the Flutter and Dart plugins to enable language support and tools for refactoring, running, debugging, and reloading your desktop app within an editor. See setting up an editor for more details.
Additional Windows requirements
For Windows desktop development, you need the following in addition to the Flutter SDK:
- Visual Studio 2019 (not to be confused with Visual Studio Code). For Win32 you need the “Desktop development with C++” workload installed, including all of its default components. For UWP you need the “Universal Windows Platform development” workload installed, with the optional UWP C++ tools.
Additional macOS requirements
For macOS desktop development, you need the following in addition to the Flutter SDK:
Additional Linux requirements
For Linux desktop development, you need the following in addition to the Flutter SDK:
The easiest way to install the Flutter SDK along with these dependencies is by using snapd. For more information, see Installing snapd.
Once you have snapd , you can install Flutter using the Snap Store, or at the command line:
If snapd is unavailable on the Linux distro you’re using, you might use the following command:
Create a new project
You can use the following steps to create a new project with desktop support.
Set up
At the command line, perform the following commands to make sure that you have the latest desktop support and that it’s enabled. If you see “flutter: command not found”, then make sure that you have installed the Flutter SDK and that it’s in your path.
is windows , macos , or linux :
For Windows UWP desktop support perform the following commands to switch to the dev channel, upgrade Flutter, and enable UWP.
To ensure that desktop is enabled, list the devices available. You should see something like the following (you’ll see Windows, macOS, or Linux, depending on which platform you are running on):
You might also run flutter doctor to see if there are any unresolved issues. It should look something like the following on Windows:
On macOS, you might see something like the following:
On Linux, you might see something like the following:
If flutter doctor finds problems for a platform that you don’t want to develop for, you can ignore those warnings. You don’t have to install Android Studio and the Android SDK, for example, if you’re writing a Linux desktop app.
After enabling desktop support, restart your IDE. You should now see windows (desktop), macOS (desktop), or linux (desktop) in the device pulldown.
Note: You only need to execute flutter config —enable-
-desktop once. You can always check the status of your configuration using the no-argument flutter config command.
Create and run
Creating a new project with desktop support is no different than creating a new Flutter project for other platforms.
Once you’ve configured your environment for desktop support, you can create and run a desktop application either in the IDE or from the command line.
Using an IDE
After you’ve configured your environment to support desktop, make sure you restart the IDE if it was already running.
Create a new application in your IDE and it automatically creates iOS, Android, web, and desktop versions of your app. From the device pulldown, select windows (desktop), macOS (desktop), or linux (desktop) and run your application to see it launch on the desktop.
From the command line
To create a new application that includes desktop support (in addition to mobile and web support), run the following commands, substituting myapp with the name of your project:
To launch your application from the command line, enter one of the following commands from the top of the package:
Note: If you do not supply the -d flag, flutter run will list the available targets to choose from.
Windows UWP
Warning: Alpha! Flutter Windows UWP desktop support is an alpha release, available on the dev channel.
To get started with Windows UWP you need to be using Windows 10. You need to install Visual Studio (not Visual Studio Code) with the “Universal Windows Platform development” workload and the optional Windows UWP C++ tools.
To configure Flutter for Windows UWP development, perform the following commands to switch to the dev channel, upgrade Flutter, and enable Windows UWP desktop support.
To create a new application, run the following commands:
Running Flutter with Windows UWP is complicated due to UWP’s sandboxed runtime. You need to run an override for the sandbox to enable the injection of Dart code into the running UWP process to enable debugging and Hot Reload.
The suggested approach during development is to first run flutter run -d winuwp from the command line, which will give you a command that you need to run from a PowerShell with Administrator privileges.
Run this checknetisolation command as shown in a PowerShell as Administrator. You can then leave this process running for the length of your development session, restarting your UWP app as required.
Once you have this process running, you can deploy to Windows UWP from within your IDE as normal, or run from the command line as follows:
Build a release app
To generate a release build, run one of the following commands:
Distribution
We don’t recommend releasing a desktop application until desktop support is stable, however, here is some information that you might still find useful.
Windows
There are various approaches you can use for distributing your Windows application. Here are some options:
- Use tooling to construct an MSIX installer (described in the next section) for your application and distribute it through the Microsoft Windows App Store. You don’t need to manually create a signing certificate for this option as it is handled for you.
- Construct an MSIX installer and distribute it through your own website. For this option, you need to to give your application a digital signature in the form of a .pfx certificate.
- Collect all of the necessary pieces and build your own zip file.
MSIX packaging
MSIX, Microsoft Windows’ application package format, provides a modern packaging experience to all Windows apps. This format can either be used to ship applications to Microsoft Windows’ Apps store, or you can distribute application installers directly.
The easiest way to create an MSIX distribution for a Flutter project is to use the msix pub package. For an example of using the msix package from a Flutter desktop app, see the Desktop Photo Search sample.
Create a self-signed .pfx certificate for local testing
For private deployment and testing with the help of the MSIX installer, you need to give your application a digital signature in the form of a .pfx certificate.
For deployment through the Windows Store, generating a .pfx certificate is not required. The Windows Store handles creation and management of certificates for applications distributed through its store.
Distributing your application by self hosting it on a website requires a certificate signed by a Certificate Authority known to Windows.
Use the following instructions to generate a self-signed .pfx certificate.
- If you haven’t already, download the OpenSSL toolkit to generate your certificates.
- Go to where you installed OpenSSL, for example, C:\Program Files\OpenSSL-Win64\bin .
- Set an environment variable so that you can access OpenSSL from anywhere:
«C:\Program Files\OpenSSL-Win64\bin» - Generate a private key as follows:
openssl genrsa -out mykeyname.key 2048 - Generate a certificate signing request (CSR) file using the private key:
openssl req -new -key mykeyname.key -out mycsrname.csr - Generate the signed certificate (CRT) file using the private key and CSR file:
openssl x509 -in mycsrname.csr -out mycrtname.crt -req -signkey mykeyname.key -days 10000 - Generate the .pfx file using the private key and CRT file:
openssl pkcs12 -export -out CERTIFICATE.pfx -inkey mykeyname.key -in mycrtname.crt - Install the .pfx certificate first on the local machine in Certificate store as Trusted Root Certification Authorities before installing the app.
Building your own zip file for Windows
The Flutter executable, .exe , can be found in your project under build\windows\runner\ \ . In addition to that executable, you need the following:
- From the same directory:
- all the .dll files
- the data directory
- The Visual C++ redistributables. You can use any of the methods shown in the deployment example walkthroughs on the Microsoft site to ensure that end users have the C++ redistributables. If you use the application-local option, you need to copy:
- msvcp140.dll
- vcruntime140.dll
- vcruntime140_1.dll
These 3 files can be found in C:\Windows\System32 if installed on your PC. Place the DLL files in the directory next to the executable and the other DLLs, and bundle them together in a zip file. The resulting structure will look something a little like this:
At this point if desired it would be relatively simple to add this folder to a Windows installer such as Inno Setup, WiX, etc.
macOS
To distribute your macOS application, you can either distribute it through the macOS App Store, or you can distribute the .app itself, perhaps from your own website. As of macOS 10.14.5, you need to notarize your macOS application before distributing it outside of the macOS App Store.
The first step in both of the above processes involves working with your application inside of Xcode. To be able to compile your application from inside of Xcode you first need to build the application for release using the flutter build command, then open the Flutter macOS Runner application.
Once inside of Xcode, follow either Apple’s documentation on notarizing macOS Applications, or on distributing an application through the App Store. You should also read through the macOS-specific support section below to understand how entitlements, the App Sandbox, and the Hardened Runtime impact your distributable application.
Linux
The executable binary can be found in your project under build/linux/ /bundle/ . Alongside your executable binary in the bundle directory there are two directories:
- lib contains the required .so library files
- data contains the application’s data assets, such as fonts or images
In addition to these files, your application also relies on various operating system libraries that it’s been compiled against. You can see the full list by running ldd against your application. For example, assuming you have a Flutter desktop application called linux_desktop_test you could inspect the system libraries it depends upon as follows:
To wrap up this application for distribution you need to include everything in the bundle directory, and make sure the Linux system you are installing it upon has all of the system libraries required. This may be as simple as:
For information on publishing a Linux application to the Snap Store, see Build and release a Linux application to the Snap Store.
As the tooling solidifies, stay tuned for updates on other ways to distribute a Linux desktop app.
Add desktop support to an existing Flutter app
To add desktop support to an existing Flutter project, run the following command in a terminal from the root project directory:
This adds the necessary desktop files and directories to your existing Flutter project. To add only specific desktop platforms, change the platforms list to include only the platform(s) you want to add.
macOS-specific support
The following information applies only to macOS development.
Entitlements and the App Sandbox
macOS builds are configured by default to be signed, and sandboxed with App Sandbox. This means that if you want to confer specific capabilities or services on your macOS app, such as the following:
- Accessing the internet
- Capturing movies and images from the built-in camera
- Accessing files
Then you must set up specific entitlements in Xcode. The following section tells you how to do this.
Setting up entitlements
Managing sandbox settings is done in the macos/Runner/*.entitlements files. When editing these files, you shouldn’t remove the original Runner-DebugProfile.entitlements exceptions (that support incoming network connections and JIT), as they’re necessary for the debug and profile modes to function correctly.
If you’re used to managing entitlement files through the Xcode capabilities UI, be aware that the capabilities editor updates only one of the two files or, in some cases, it creates a whole new entitlements file and switches the project to use it for all configurations. Either scenario causes issues. We recommend that you edit the files directly. Unless you have a very specific reason, you should always make identical changes to both files.
If you keep the App Sandbox enabled (which is required if you plan to distribute your application in the App Store), you need to manage entitlements for your application when you add certain plugins or other native functionality. For instance, using the file_chooser plugin requires adding either the com.apple.security.files.user-selected.read-only or com.apple.security.files.user-selected.read-write entitlement. Another common entitlement is com.apple.security.network.client , which you must add if you make any network requests.
Without the com.apple.security.network.client entitlement, for example, network requests will fail with a message such as:
Important: The com.apple.security.network.server entitlement, which allows incoming network connections, is enabled by default only for debug and profile builds to enable communications between Flutter tools and a running app. If you need to allow incoming network requests in your application, you must add the com.apple.security.network.server entitlement to Runner-Release.entitlements as well, otherwise your application will work correctly for debug or profile testing, but will fail with release builds.
For more information on these topics, see App Sandbox and Entitlements on the Apple Developer site.
Hardened Runtime
If you choose to distribute your application outside of the App Store, you need to notarize your application for compatibility with macOS 10.15+. This requires enabling the Hardened Runtime option. Once you have enabled it, you need a valid signing certificate in order to build.
By default, the entitlements file allows JIT for debug builds but, as with App Sandbox, you may need to manage other entitlements. If you have both App Sandbox and Hardened Runtime enabled, you may need to add multiple entitlements for the same resource. For instance, microphone access would require both com.apple.security.device.audio-input (for Hardened Runtime) and com.apple.security.device.microphone (for App Sandbox).
For more information on this topic, see Hardened Runtime on the Apple Developer site.
Plugin support
Flutter on the desktop supports using and creating plugins.
Using a plugin
To use a plugin that supports desktop, follow the steps for plugins in using packages. Flutter automatically adds the necessary native code to your project, as with iOS or Android.
We recommend the following plugins, which have been updated to work for desktop apps:
Use the following links to find all packages on pub.dev that support desktop apps. These links lists all packages, not just plugin packages. (Remember that plugin packages, or plugins, provide an interface to platform-specific services.)
Writing a plugin
When you start building your own plugins, you’ll want to keep federation in mind. Federation is the ability to define several different packages, each targeted at a different set of platforms, brought together into a single plugin for ease of use by developers. For example, the Windows implementation of the url_launcher is really url_launcher_windows , but a Flutter developer can simply add the url_launcher package to their pubspec.yaml as a dependency and the build process pulls in the correct implementation based on the target platform. Federation is handy because different teams with different expertise can build plugin implementations for different platforms. You can add a new platform implementation to any endorsed federated plugin on pub.dev, so long as you coordinate this effort with the original plugin author.
For more information, including information about endorsed plugins, see the following resources:
- Developing packages and plugins, particularly the Federated plugins section.
- How to write a Flutter web plugin, part 2, covers the structure of federated plugins and contains information applicable to desktop plugins.
- Modern Flutter Plugin Development covers recent enhancements to Flutter’s plugin support.
- Federated Plugin proposal
Samples and codelabs
You can run the following samples as desktop apps, as well as download and inspect the source code to learn more about Flutter desktop support.
Flutter Gallery running web app, repo A samples project hosted on GitHub to help developers evaluate and use Flutter. The Gallery consists of a collection of Material design widgets, behaviors, and vignettes implemented with Flutter. You can clone the project and run Gallery as a desktop app by following the instructions provided in the README. Flokk announcement blogpost, repo A Google contacts manager that integrates with GitHub and Twitter. It syncs with your Google account, imports your contacts, and allows you to manage them. Photo Search app A sample application built as a desktop application that uses the following desktop-supported plugins:
- file_chooser
- menubar
- url_launcher
Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the BSD License.
Источник