Bazel not running flutter correctly - flutter

I'm trying to execute a flutter command using bazel. This is my BUILD.bazel file:
genrule(
name = "flutter_build",
srcs = [
"//:root_filegroup"
],
outs = ["out.txt"],
cmd = "flutter build ipa --export-method development"
)
The command flutter build ipa --export-method development works perfectly if I run it directly in my iterm, but for some reason the same command in bazel returns a permission error:
Flutter failed to open a file at "/Users/rlanhe/tools/flutter/flutter/bin/cache/lockfile".
Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.
Try running:
sudo chown -R $(whoami) /Users/rlanhe/tools/flutter/flutter/bin/cache/lockfile
Well, doesn't make sense to me, since that folder already have correct permission and I'm able to run the command outside bazel.

Integrating Flutter/Dart and Bazel is likely a large amount of work.
There's an issue here about it:
https://github.com/flutter/flutter/issues/19680
And it looks like there are some dart rules here:
https://github.com/cbracken/rules_dart
The immediate issue you're running into is that Bazel runs each action (i.e. build step) in a sandbox, so unless an input to the action is declared, it's not going to be in the sandbox. You can maybe get further by adding tags = ["no-sandbox"] to the genrule, (see https://bazel.build/reference/be/common-definitions#common.tags).
This is essentially running one build system inside another, and this isn't going get the caching and incrementality benefits of Bazel, because Bazel has no insight into what happens inside the genrule. Unless you have some higher-level plans to integrate this into a larger repository that uses Bazel, there isn't much benefit here compared to running flutter directly or in a shell script.

Related

Flutter command works locally but not on Github Actions

I have a problem where a command that works on my local machine isn't working on GitHub Actions.
The command I'm using on my local machine is:
flutter build appbundle --obfuscate --split-debug-info=build/app/outputs/ --flavor Production --dart-define="ENVIRONMENT=PRODUCTION"
This command exists in the yml. If I change it to flutter build apk then it works with no problem.
However, when trying to build the aab I get the error:
Gradle build failed to produce an .aab file. It's likely that this file was generated under /home/runner/work/{project-name}/{project-name}/build, but the tool couldn't find it.
I'm not sure why it's put the project name in there twice, and I don't know if it's the cause or it's what it's supposed to be.
When I looked up the error I found people saying it's because I didn't specify the flavour. Clearly I have specified the flavour, so I'm confused as to what's happening.

How to install and run flutter without network connection?

I installed flutter on a machine with a network, all tests and commands ( doctor, create, test ) run without problems. Then he took the directory where flutter was located and transferred it to a machine without an Internet connection. But with any call to flutter, it goes into
Running "flutter pub get" in flutter_tools.."
And does not leave this process. If you run it with the -vv flag, you can see that there is Resolving dependencies... The --offline flag does not help. I also tried to take .config, .pub-cache, .flutter from the machine where there is a connection and transfer it to the working one, but this did not help either. The question is, is there anything else that can be dragged and dropped as a dependency, or is there another way to run flutter offline?
Both machines are running Debian 9.
As I thought, all this is possible. The problem is in the wrong paths. When transferring the flutter working directory to another PC, you need to make sure that the paths are identical. Because in *packages/flutter_tools/ files there are many links in files on paths that correspond to downloads from the first machine.
Total what needs to be done:
Update flutter and dart
Run flutter precache
Copy the entire directory where flutter is located and ~$HOME/.pub-cache
Create the same path on the new machine and transfer the files.
Perform all necessary operations with the --offline flag

Flutter Windows Desktop app gets stuck on white screen after msix installation

Background
I just developed my first flutter desktop app for a windows machine. The app is working fine while developing/debugging it, but I am trying to test it as an application in release mode.
What’s done
I created an msix using pub msix.
For signing, I have tried both my
own certificate and the test certificate that comes with msix
packages by default.
I have tried both stable and beta channels.
Actual Problem
When I install the app on the other system (or even on the actual system where I debugged the app). I can install the msix setup successfully I can see my app listed in the apps, but when I try to open it, it is stuck on a blank/white screen. There is no UI rendered. And if I try to maximize the window, it goes to App not responding state.
Any help will be really appreciated.
Thanks in advance.
Update / New Finding
After going through the links provided by Yehuda Kremer and pulling my hair for a few days, I found the answer in this tweet
https://twitter.com/FilledStacks/status/1436280577439715338?s=20
So the main issue is that app is using some absolute paths that don't work on other machines (after release)
1- My app was using a database, so I have made sure that that database path is relative to the application document directory.
2- Now the build is also referring to some dependencies and their paths are also absolute. I have noticed a flag CMAKE_INSTALL_LOCAL_ONLY in the cmake_install.cmake but that flag is not being set anywhere.
Here is the log of flutter build windows -v
https://pastebin.com/LAeshUMY
-- Now I am looking for a proper way to convert all the paths to relative so that the build is ready for installation on different machines, instead of local installation only.
I have found the solution.
The main problem was that the app was looking for some dependencies and it was unable to find them. As mentioned here.
The reason for not finding that in release mode can be one of the following,
You are using some dll (package that depends on a dll) that is available on a specific path in your system, but when you are release the app that (absolute) path is not valid anymore.
You are adding some asset with absolute path (that is only applicable to your system).
Solution:
If it is a dll, you should be adding that to the release folder. In my case it was sqlite3.dll
If it is some other asset then you should always use the relative path.
You mentioned msix package, let see if the problem is in the app or in the packaging process
run flutter build windows without the flutter pub run msix:create, then run the created .exe file to see if its work.
btw this issue mention here: https://github.com/flutter/flutter/issues/74507
and here (the 'maximizing' problem): Black screen appears on maximizing and minimizing flutter desktop app

Flutter error: Unable to locate gradlew script

I can't run all of my flutter apps, because in the console appears everytime this error message:
Downloading Gradle Wrapper... 1,2s
Launching lib\main.dart on SM G960F in debug mode...
Running Gradle task 'assembleDebug'...
Finished with error: Unable to locate gradlew script. Please check that C:\Users\...\android\gradlew.bat exists or that C:\Users\...\android can be read.
I try to fix this problem more than ten hours and don't find a solution.
I will advise you to check your pc properly for unwanted programs. Something is preventing your pc from running the Gradle. I had the same issue only to realize that antivirus was installed on my pc alongside a cd burner that I just installed. Check for any antivirus that might be preventing Gradle from running.
I also faced the same error initially. While creating a flutter application from scratch I just ran the default flutter application which is a counter app in a flutter. I faced the same issue at first. If you are in this same context as described earlier the following could be the solution
1.Java 8 is more suitable for the flutter/android development. The next versions of java have some exceptions. I used the Java 14 and stuck at this issue for some time
The next could be the JAVA_HOME path in your environment variables. If it is not provided the set the JAVA_HOME path.
Run flutter --doctor and check the requirements if satisfied like Android SDK is updated or not, upgrade flutter if required. In some cases having good Internet connection also plays a role in this issue some times.
These are the major points to be satisfied in order to get rid of this error. Mostly this could be the a solution or part of it.
The error suggests that something is preventing gradle to run properly on your machine. Check whether you have any unwanted programs or anti-virus on your machine running that might be preventing gradle to run. If so, remove or stop those programs / anti-virus and try again.
After that, delete the .gradle folder located here C:\Users\yourPcName\.gradle containing the unfinished file and try again . It will work now .
You can also manually download Gradle and map it in Android studio , Learn more with this article here .
Warning, the gradle versions change quickly, so make sure you manually
downloaded the exact version that flutter wanted to download and the
download failed. Download the gradle here and then replace it in the
gradle folder.
C:\Users\yourPcName\.gradle\wrapper\dists\gradle-x.x.x-all
If it still doesn't work,
Try to run flutter --doctor
From a console window that has the Flutter directory in the path (see above), run the following command to see if there are any platform dependencies you need to complete the setup:
C:\src\flutter> : flutter doctor
This command checks your environment and displays a report of the status of your Flutter installation. Check the output carefully for other software you might need to install or further tasks to perform (shown in bold text).
You can learn more here :
If flutter doctor itself doesn't work, then know that flutter is not installed on your machine (or you forgot to add it to the environment
variable).
I also faced this problem and I made something to run my app on android
tried to open anything on android files and android studio ask me if I want to open for editing android file in android studio then click on it and it will open android project then click run enter image description here

Squarespace Local Development doesnt seem to want to work

I am following the developers.squarespace.com documentation and I am trying to use a local dev environment to make my static website into a squarespace template. As far as getting the server started, everything is working fine until I get to the point of installing the squarespace server to my system. To beging, I use this command in my Mac's terminal:
npm install -g #squarespace/server
After I enter this, everything once again seems to be working correctly because I am met with this (which doesn't show any errors as I have seen for others):
Executing: npm run bundle
> #squarespace/server#1.1.2 bundle /Users/Squid/.npm-global/lib/node_modules/#squarespace/server
> node scripts/bundlejre.js --accept --clear -tz -j 8u131 -o build/distributions/runtimes/jre
Bundling compatible JRE (This may take a while)
> #squarespace/server#1.1.2 cleanupscript /Users/Squid/.npm-global/lib/node_modules/#squarespace/server
> node scripts/execif.js --os=win32 --exists=build node scripts/vetolines.js build/distributions/local-developer/bin/run.bat #!
+ #squarespace/server#1.1.2
updated 1 package in 56.891s
Following that, I clone my site into a folder on my desktop from git and then navigate to the folder in terminal. At this point, I attempt to start the Dev Server, by running the following command(with the "site-name" changed to my site's name:
squarespace-server https://site-name.squarespace.com
My problem begins here, I am met with the following response from the terminal:
-bash: squarespace server: command not found
My mac doesn't recognize the server, even though I found the folder manually on my computer (but I don't know what to do with it).
So far I have attempted a couple troubleshooting methods:
I have a trial site so I tried to use the --auth flag as suggested on the documentation.
I restarted the whole process, so I removed all node and squarespace related files from my system and started again.
After looking online for answers, I installed homebrew to make sure that I am installing node and git correctly to my system.
Finally, I have attempted to change permissions for npm (but I'm not sure that I did this part correctly or not since I don't receive any permission errors).
Also, thank you so much for reading through all this. I just really wanted to make sure you all understood where I was at in this whole process.
I think you can solve this by adding an export path to your profile.
Open the terminal
Enter the following command
touch ~/.bash_profile
(this creates the bash profile)
open ~/.bash_profile
(this opens the bash profile you just created)
Your bash profile will open in a text editor.
Add the following line, then save:
export PATH=~/.npm-global/bin:$PATH
Restart terminal and try using the command again. < This part is important. If you don't restart your terminal it won't recognise the profile.
https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally