Error when building flutter app for Linux snap package using snapcraft - CMake step failing

2k views Asked by At

This question has been asked here and (erroneously) closed as a duplicate with a link to an old CMAKE question. Probably the closing person did not read the question properly. This has nothing to do with plain CMake configuration, unless you want to configure the CMake use in snapcraft source code.

Error when building flutter app for Linux snap package using snapcraft

The fact is that running snapcraft fails. Running it with --debug gives you a root console of the snapcraft / multipass filesystem, whoami says root, but you only see the snap things around (for instance, not your home). Anyways, the error says

CMake Error: The current CMakeCache.txt directory /root/parts/xxxxx/build/build/linux/release/CMakeCache.txt is different than the directory
/home/zolal/flutterapps/xxxxx/build/linux/release where CMakeCache.txt was created. This may result in binaries being created in the wrong
place. If you are not sure, reedit the CMakeCache.txt 

(naturally, you cannot reedit the CMAKECache.txt, because this is created by snapcraft)

It seems that the cmake build starts outside of the snapcraft / multipass VM, and than moves to the multipass VM resulting in CMake error. Because the original question was asked a while ago, obviously this still does not work. Did anyone solve this problem alredy?

Update, purged multipass and tried with lxd:

snapcraft --use-lxd
Launching a container.
Waiting for container to be ready
Waiting for network to be ready...
snap "snapd" has no updates available
The flutter plugin is currently in beta, its API may break. Use at your own risk.
snapd is not logged in, snap install commands will use sudo
snap "core18" has no updates available
Skipping pull flutter-extension (already ran)
Skipping pull geraspine-outcome-pc (already ran)
Skipping pull gnome-3-28-extension (already ran)
Skipping build flutter-extension (already ran)
Building geraspine-outcome-pc 
flutter pub get
   Woah! You appear to be trying to run flutter as root.
   We strongly recommend running the flutter tool without superuser privileges.
  /

Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
Failed to run 'flutter pub get' for 'geraspine-outcome-pc': Exited with code 1.
Verify that the part is using the correct parameters and try again.
Run the same command again with --debug to shell into the environment if you wish to introspect this failure.

Naturally, the pubspec.yaml is there, but the files are obviously not transferred to the VM.

4

There are 4 answers

4
Manish Dhruw On BEST ANSWER

Delete build directory and build again.

src github-issue

1
LuminousLizard On

The solution is to execute following command inside your flutter project root folder (where the build, lib, snap, etc. folders are contained):

snapcraft clean <project-name>

This deletes the build cache inside "/root/parts/>project-name>" folder.

Should that not be enough, you can clean the whole snapcraft parts folder with

snapcraft clean

but this includes all dependencies. This means that all dependencies must be downloaded again the next time you compile your project.

Then delete the whole folder of your_part_name under parts folder

This doesn't work because the "parts" folder is inside "/root" dir and we cannot access or delete the stuff inside manually.

But it would be nice if we can change the parts folder e.g. into our /home dir. But I haven't found any possibilities yet !

0
Thiago Barcala On

For me it was important to delete the build directory in my local directory also:

rm -rf build && snapcraft clean <project> && snapcraft
0
yingshao xo On

If you got any error when building this, just run snapcraft build --debug

Then delete the whole folder of your_part_name under parts folder