Go-flutter: Release builds

Created on 9 Jun 2019  路  39Comments  路  Source: go-flutter-desktop/go-flutter

I use the hover build command to generate a Windows executable, but there is a black console, how to publish a real program without a console.

enhancement hover

Most helpful comment

I am really looking forward to this as well.

All 39 comments

We don't have support for releases yet. For now, hover only builds a debug version of the app with a console to track logs. I'll keep this issue open to track support for release builds.

Things that --release should do:

  • [x] Build binary without console (windows: -ldflags -H=windowsgui).
  • [x] Building flutter bundle as --release.
  • [x] Setting the right VM arguments.
  • [x] Reduce the size of the share-lib from 88M to 28M by running strip -s ./libflutter_engine.so.

I am really looking forward to this as well.

Can't wait to play with it.

@GeertJohan Any updates or ETA on this? If not, would you be able to provide any documentation on how to go about removing the console window manually for now? It would be greatly appreciated.

Thanks.

Once my final exams are over, I'll like to take a look at release builds, (if it's not done by then).
For now, #135 provides enough information for you to hack this through.

$ # export CGO_LDFLAGS="-L$HOME/.cache/hover/engine/windows/" # Not working!
$ # set CGO_LDFLAGS="-L%HOMEPATH%/.cache/hover/engine/windows/" # also not working the dll isn't found
$ cd ./desktop/cmd
$ go build -ldflags="-L%HOMEPATH%/.cache/hover/engine/windows/" -H=windowsgui
$ mv cmd ../build/outputs/windows
$ ../build/outputs/windows/cmd # to start the app

@Drakirus Thanks for that. Im assuming its supposed to be set vs export for windows?

Yup

Im getting the following error:

PS C:\Users\User\development\desktop-apps\flutter_project> set CGO_LDFLAGS="-L%HOMEPATH%/.cache/hover/engine/windows/"
PS C:\Users\User\development\desktop-apps\flutter_project> cd ./desktop/cmd
PS C:\Users\User\development\desktop-apps\flutter_project\desktop\cmd> go build -ldflags -H=windowsgui
# github.com/go-flutter-desktop/go-flutter/embedder
C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lflutter_engine
collect2.exe: error: ld returned 1 exit status

@Drakirus That worked, thank you!

For anyone having this issue, copying the flutter_engine.dll file to the lib folder of minwg did the trick.

windows env var command:

set CGO_LDFLAGS="-L%HOMEPATH%/.cache/hover/engine/windows/"

It doesn't work

$ set CGO_LDFLAGS="-L%HOMEPATH%/.cache/hover/engine/windows/"
$ go build -ldflags -H=windowsgui
# runtime/cgo
gcc: error: "-L\Users\cheng/.cache/hover/engine/windows/": Invalid argument

I just copy flutter_engine.dll to {mingw64 installation place}\lib and it works.

cd ./desktop/cmd
go build -ldflags -H=windowsgui
mv cmd ../build/outputs/windows
../build/outputs/windows/cmd

@Drakirus When building for OSX with hover, it seems as though the -mmacosx-version-min gcc flag is not being set, how would I go about making hover set it?

Things that --release should do:

  • [x] Build binary without console (windows: -ldflags -H=windowsgui).
  • [x] Building flutter bundle as --release.
  • [x] Setting the right VM arguments.
  • [x] Reduce the size of the share-lib from 88M to 28M by running strip -s ./libflutter_engine.so.

How is the progress of this feature? I am looking expectantly toward the feature.
And use -ldflags "-s -w -H=windowsgui" could reduce the size even more.

For Windows

cd C:\your_project_dir\desktop\cmd
C:\your_project_dir\desktop\cmd>go build -ldflags -H=windowsgui
C:\your_project_dir\desktop\cmd>move cmd.exe ../build/outputs/windows
C:\your_project_dir\desktop\build\outputs\windows\cmd.exe

Thank you all. you are amazing.

FYI, Work in progress in branch feature/release, not completed yet.

https://github.com/go-flutter-desktop/hover/pull/11 got merged!
Hover, when building the app with hover build will create the app in release mode!

Updates on hover occurs, make sure to run go get -u github.com/go-flutter-desktop/hover every once in a while.

Does Mac and Linux supported yet? Still get console windows in mac.

@deromask: Answer copy/pasted from zserge/webview issue 13:

On windows there are two subsystems, console and windows. They often have two different entry points (main vs WinMain). But on MacOS it's all the same executable.

The reason you see a terminal window is because you launch the binary directly and not as an app bundle.

Try running the following commands:

$ cd desktop/build/outputs/darwin
$ mkdir -p minimal.app/Contents/MacOS
$ cp ${your_app_name} minimal.app/Contents/MacOS/minimal

Now in Finder you should see minimal.app, clicking on that would launch a GUI window without a terminal. Of course, for a more proper app you would also have to add minimal.app/Contents/Info.plist XML file and maybe some minimal.app/Contents/Resources/minimal.icns for icons. But that depends on the way you package/distribute your app, and I don't think library should be responsible for such things.

Some more readings: https://stackoverflow.com/questions/23861914/how-to-hide-terminal-window-in-mac-osx.
The process of building this app bundle is tracked in: #207

@Drakirus Thank you very much!

How to update previous installed device.

go get -u github.com/go-flutter-desktop/hover

This gives following error

go get -u github.com/go-flutter-desktop/hover
# cd C:\Users\acer\go\src\github.com\go-flutter-desktop\hover; git pull --ff-only
error: Your local changes to the following files would be overwritten by merge:
        assets/app/icon.png
Please commit your changes or stash them before you can merge.
Aborting
package github.com/go-flutter-desktop/hover: exit status 1

Thank You

@maheshbhattaraai

cd C:\Users\acer\go\src\github.com\go-flutter-desktop\hover
git stash
go get -u github.com/go-flutter-desktop/hover

@Drakirus Any luck figuring out the -mmacosx-version-min flag issue?

At the moment, it seems to be set to whatever OS version is used to build. I could try setting the ENV variable to CGO_CFLAGS="-mmacosx-version-min=10.11" and do hover build, im just not sure if this variable is overwritten by the hover build process.

@alexelisenko if you build your own version of hover and add the -mmacosx-version-min=10.11 flag in build.go#L195, does it fixes your issue?

I can give it a shot. Would you be able to give instructions on building and using a custom version of hover?

git clone https://github.com/go-flutter-desktop/hover.git cd hover go install

I think I have it working, but need to do some more testing.

I had to add the following:

ldflags = append(ldflags, "-extldflags=-mmacosx-version-min=10.11")

and

    cmdGoBuild.Env = append(os.Environ(),
        "GO111MODULE=on",
        "CGO_CFLAGS=-mmacosx-version-min=10.11",
        "CGO_LDFLAGS="+cgoLdflags,
    )

Is there a way to use something like ::ShowWindow(::GetConsoleWindow(), SW_HIDE); to hide console? I got a fairly big issue when using release mode.

On debug mode, There is no console window when using dart Process, but on release mode, This is the biggest problem, I use a bunch of Process.run in the background, so It popup up several console in a const interval because Timer.periodic is calling constantly.

Except that, I can't find how to set icon to the final executable, Am I missing something?

By the way, Thanks for this project 馃憤 , It's awesome.

@Tokenyet Does the process you are executing open with a console window (if you run it manually)?

If anyone can correct me if I'm wrong, but, I believe that if you execute a process that opens a console window, that is your issue.

You can set your icon with same icon name previously stored inside desktop/assets/.

I don't know what you think, but what I mean is If I build a Debug executable, It's only one console, no any popups. This is only happened in Release mode.

You can set your icon with same icon name previously stored inside desktop/assets/.

Override icon.png will only replace the icon of the windows bar, not the executable itself in my case.

@Tokenyet Have you tried setting the runInShell argument to true?

@Tokenyet Have you tried setting the runInShell argument to true?

That's what I'm doing.

With the following code, I made It! This is the hiding solution to solve the popup issue.

package main

import "github.com/gonutz/w32"

func main() {
    console := w32.GetConsoleWindow()
    if console != 0 {
        _, consoleProcID := w32.GetWindowThreadProcessId(console)
        if w32.GetCurrentProcessId() == consoleProcID {
            w32.ShowWindowAsync(console, w32.SW_HIDE)
        }
    }
}

reference: https://stackoverflow.com/questions/23250505/how-do-i-create-an-executable-from-golang-that-doesnt-open-a-command-cmd-wind/23250506

Sorry, but I can only find the workaround, I think someone would interest on this, so I decided to share here.

For changing executable icon, following the instruction on rc-demo, and run hover build, that's It.

reference: https://stackoverflow.com/questions/25602600/how-do-you-set-the-application-icon-in-golang/49127938#49127938

Was this page helpful?
0 / 5 - 0 ratings

Related issues

inaxium picture inaxium  路  4Comments

ghost picture ghost  路  6Comments

pchampio picture pchampio  路  6Comments

pauldemarco picture pauldemarco  路  7Comments

pchampio picture pchampio  路  3Comments