Flutter command works locally but not on Github Actions - flutter

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.

Related

Bazel not running flutter correctly

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.

Is there a way to apply Flutter build_runner to dependencies?

I have a Flutter app project app and a dependency project lib that contains generated code by
json_serializable, built_value, etc..
app builds successfully when lib has generated code like source.g.dart.
But when source.g.dart does not exists, app build failed and I have to rerun build_runner on lib.
And I'm going to host lib on GitLab and don't want to track *.g.dart on git.
So, every time I clone or pull code that needs code generation from GitLab, I must remember to run build_runner on lib or get error:source.g.dart does not exists.
Off course I can write script like below.
run build_runner on lib
build app
But I believe there is a better way to tell the build system from lib,
Hey, I want to run build_runner on me.
Is this possible ?
If so, please let me know.

Lefthook error: flutter command not found

I switched from GitHub Desktop to Sourcetree due to some missing feature.
On my flutter project, I installed LeftHook to execute a linter when someone commits something.
On GitHub Desktop, Lefthook works well, but when I try to commit from SourceTree, the error sh: flutter: command not found
I can't understand why. The flutter SDK path is set globally correctly (i can use flutter commands in every terminal)
Problem solved!
Seems like that Sourcetree isn't capable to access to the PATH in witch flutter is contained (the one added in the file .zshrc).
So the solution is to add the export in every hook that lefthook uses,
something like this:
#!/bin/sh
export PATH="$PATH:/Users/.../flutter/bin"
if [ "$LEFTHOOK" = "0" ]; then
...

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

VS Code Extension tests not found on Azure Pipeline

I have an extension, initially created using the standard yo code template, and successfully uploaded to the market place. I have created a test suite, which works correctly when running locally (i.e. pressing F5), and I now wanted to add CI testing to the Github repo.
I followed the instructions on Continuous Integration and created a config file. The extension now builds successfully, however it appears that no tests are discovered.
For example, in this build I intentionally introduced a failing test, but it still passes.
Is there a step I'm missing or a good way to debug the problem?
See the Issue I opened for the answer. Currently, the tests fail silently if you do not have the required dependencies listed.