go-flutter-desktop / go-flutter

Flutter on Windows, MacOS and Linux - based on Flutter Embedding, Go and GLFW.
https://hover.build/
BSD 3-Clause "New" or "Revised" License
5.86k stars 282 forks source link

Unable to build anything (no .packages file) #681

Open MrCyjaneK opened 1 year ago

MrCyjaneK commented 1 year ago

Hover doctor

$ flutter doctor
Flutter 3.6.0-0.1.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision 75927305ff (3 tygodnie temu) • 2022-11-17 05:52:50 +0530
Engine • revision b754eabc98
Tools • Dart 2.19.0 (build 2.19.0-374.1.beta) • DevTools 2.19.0
[...]

Error output

Using hover build [...] --XXX to build my application, I get the following error:

hover: Generating kernel snapshot
result 97ec1709-f58d-434b-b3b3-f41ff40bad12
Error: Error when reading '.packages': No such file or directory
Error: Error when reading '.packages': No such file or directory
[...]

How to reproduce?

$ flutter create testapp
$ cd testapp
$ flutter run --device-id linux # confirm that the app runs
$ hover init
$ hover build linux # press y when asked

Build will fail.

MrCyjaneK commented 1 year ago

to fix:

create generate_dot_packages.dart in project root directory with following content:

import 'dart:convert';
import 'dart:io';

Future<void> main() async {
  File file = File(".dart_tool/package_config.json");
  dynamic pkgconfig = jsonDecode(await file.readAsString());
  List<dynamic> pkgs = pkgconfig["packages"];
  for (var elm in pkgs) {
    if (elm["rootUri"] == "../") {
      elm["rootUri"] = "./";
    }
  }
  pkgconfig["packages"] = pkgs;
  print(jsonEncode(pkgconfig));
}

run:

$ dart run generate_dot_packages.dart > .packages

hover build linux-appimage should work.

evorts commented 1 year ago

I face the same issues and your fix suggestion save the day. thank you!