is there a flutter cli command that installs all sdks for a specific project? - flutter

the use case is as follows, I am trying to setup a pipeline for an app we are working on . I have noticed that when running the pipeline most of the time is consumed by downloading the relevant android SDKs for the app. since the allowed cache size is limited I was wondering if is a way to perform everything that is done at the start of flutter build appbundle so I can prepare a specific docker image to be used by the pipeline as the build goes much faster without the downloading of all of these sdks.
using flutter build appbundle is what I am doing right now but it makes the image building process slow.
something like :
flutter prepare
note that simply running pub get is not enough
asking here before I create a feature request on https://github.com/flutter/flutter
looked at flutter cli documentation but couldn't find anything.

Related

How can I run flutter web app without internet connection

I created a flutter web application,
and I finished building it with the command ..
flutter build web --release ,
and then transferred it to a local server ,
The site does not work unless it is connected to the Internet ,
I want the site to work without an internet connection ,
As I work in an organization and some users do not have internet permissions .
Please, I want a solution to this problem .
Thanks
The problem is, that flutter has some dependencies, that can not be resolved when you, as the client, are offline. Mostly consisting of canvaskit and certain google fonts.
There are multiple solutions for that. The easiest being to use the html web-renderer:
flutter build web --release --web-renderer html
this should work for most applications, however it has lower performance than canvaskit, especially with high widget density.
Therefore you can also use canvaskit locally as it is automatically built when you build your release. But you have to set it as base url, by adding the following lines in your index.html:
<script>
window.flutterConfiguration = {
canvasKitBaseUrl: "/canvaskit/"
};
</script>
This makes sure your flutter application uses the local source for canvaskit. However, another problem could be the usage of google fonts, e.g. Roboto, as those often need to be downloaded as well. But you can just add those to the pubspec.yaml explicitly to account for that, like explained here.
Some sources for more informations:
flutter web-renderers
The same issue but on github
Making Flutter offline capable
Download and set locally from asset policy for your web application
Add link to local Canvaskit as bellow :
flutter build web --web-renderer=canvaskit
--dart-define=FLUTTER_WEB_CANVASKIT_URL=/canvaskit/
To make it work for a dev build, I incorporated Spanching's answer above in the following steps.
Run: flutter clean to clean up all build cache (this is important to have canvas kit re-downloaded in step 4 below).
Run: flutter pub get to download packages per pubspec.yaml
If you're using build runner: dart run build_runner build --delete-conflicting-outputs
At this stage you should have a clean /build folder (I also have an ios sub-folder as I'm also developing for iOS)
Run: flutter build web
At this stage you should have a clean /build/web added with a canvaskit folder underneath it. Full path: /build/web/canvaskit/
Then:
Open index.html under /web (note - do not open the one under /build/web)
Add the script mentioned in the answer above to the body of the html file. I just added it above the existing script that's already there.
Run your project in deubg mode (with Wifi turned off).

I get this error in my flutter app. migrate this app to the V2 embedding

I get this error in my Flutter Project,
C:\src\flutter\bin\flutter.bat --no-color pub get
Running "flutter pub get" in source_code... 34.3s
This app is using a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, try to migrate this app to the V2 embedding.
Take a look at the docs for migrating an app: https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects
The plugin firebase_core requires your app to be migrated to the Android embedding v2. Follow the steps on https://flutter.dev/go/android-project-migration and re-run this command.
Process finished with exit code 1
Flutter Embedding Error
Since Flutter 1.12 the way how Flutter plugins communicate with the native Android side has been improved. Allowing plugins to better integrate with the native Android lifecycle.
Some plugins support both the new and the old structure, however many plugins (like firebase_core) dropped support for the legacy structure to ensure optimal integration with the Android system.
Apps created using Flutter 1.12 and higher automatically generate the correct Android integration logic, however Flutter applications created with an earlier version of Flutter need to be manually migrated. There are two options to fix this for your app:
The easiest solution is to delete the android folder in your project and let Flutter (using Flutter 1.12 or higher) recreate it for you by running the following command in the root folder of the Flutter project: flutter create --platform=android . (don't forget the . at the end of the command). You should only do this if you haven't made any custom changes to the Android code and of course make sure to make a backup first.
The more safe option is to manually migrate the Android project using the instructions provided on the GitHub Wiki page mentioned in the error message.
When following the instructions on the GitHub Wiki page make sure to keep an eye on all the details. Personally I forgot to update the <application android:name="MyApp" to the recommended <application android:name="${applicationName}" which resulted in the same error you are reporting.
What helped me was to create a new "dummy" application with the latest version of Flutter (for example flutter create --platforms=android test_app) and compare the files in the Android folder with the files of my current App and make changes where necessary.

Can I check SkSL bundle engine version with Flutter?

I have recorded SkSl script to warmup shaders. I use this build option to apply it for my Flutter app's release builds:
flutter build appbundle --release --bundle-sksl-path flutter_01.sksl.json
It works great, but it stops work when new Flutter version released. In that case I have an error:
Expected Flutter b8752bbfff0419c8bf616b602bc59fd28f6a3d1b, but found 2c956a31c0a3d350827aee6c56bb63337c5b4e6e
The SkSL bundle was produced with a different engine version. It must be recreated for the current Flutter version.
I want to detect this error without building my release app (as a merge check on CI).
The question: is it possible?

How do I minimize the size of a Flutter Web Release? Is the NOTICES File required?

My web folder after building my Flutter Web app comes to 5.4MB which isn't too bad, but I might as well optimize.
I was wondering if anybody has any tips outside the obvious(removing unnecessary packages), to minimize the file size? I'll be hosting on Firebase.
Also, there is a NOTICES file which is about 1MB filled with random licenses/copyright disclaimers, are there any consequences to deleting this?
Is flutter build web all you do to build a release version? Is there anything else that should be done other than flutter clean?
According to flutter document, There is a option available for all platforms
but not available for web so far. Read the full document
This command will help you to get a minimized size of build except web
flutter build apk --analyze-size
flutter build appbundle --analyze-size
flutter build ios --analyze-size
flutter build linux --analyze-size
flutter build macos --analyze-size
flutter build windows --analyze-size

Flutter release apk

I would like to know if the apk file produced from running the flutter run --release command is different from flutter build apk. Which is better for uploading to the playstore.? I just tried both commands and the difference in apk size is really huge. The release command produces a far smaller apk size.
In summary what I want to know is since
Flutter build apk =>> fat apk.
Does
Flutter run --release =>> split apk?
flutter run --release: builds a release version of the app and starts it directly, then shows the console UI to manipulate the running instance.source flutter wiki
Use release mode for deploying the app, when you want maximum optimization and minimal footprint size. For mobile, release mode (which is not supported on the simulator or emulator), means that:
Assertions are disabled.
Debugging information is stripped out.
Debugging is disabled.
Compilation is optimized for fast startup, fast execution, and small package sizes.
Service extensions are disabled.
(apps are smaller)
flutter build apk results in a fat which is a single APK that contains binaries for multiple ABIs embedded within it. This has the benefit that the single APK runs on multiple architectures and thus has wider compatibility, but it has the drawback that its file size is much larger, causing users to download and store more bytes when installing your application. When building APKs instead of app bundles, it is strongly recommended to build split APKs
Although app bundles are preferred over APKs, there are stores that don’t yet support app bundles
When should I build app bundles versus APKs?
The Google Play Store recommends that you deploy app bundles over APKs because they allow a more efficient delivery of the application to your users. However, if you’re distributing your application by means other than the Play Store, an APK may be your only option.
read more from the docs
You can split apks with this command
flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi