How to use libflutter_linux_glfw.so file and related files from out/host_debug of flutter engine - flutter

I followed instructions from Setting up the Engine development to build the flutter engine. Purpose of this was to use the texture support from Texture support for glfw. I could compile the flutter engine.
Next I wanted to use this engine and develop Texture based application. While compiling using the following command, I see that libflutter_linux_glfw.so and other platform files are copied from flutter/bin/cache/artifacts/engine.
flutter build linux
I added the dependency_overrides to pubspec.yaml as follows. But, no luck.
dependency_overrides:
sky_engine:
path: <base folder of engine>/engine/src/out/host_debug_unopt/gen/dart-pkg/sky_engine
sky_services:
path: <base folder of engine>/engine/src/out/host_debug_unopt/gen/dart-pkg/sky_services
Looking forward for the suggestions on the changes required to use files from engine/src/out/host_debug_unopt.

I could use compiled libflutter_linux_glfw.so by using --local-engine-src-path and --local-engine options of flutter given in the following link.
Using a locally-built engine with the flutter tool

Related

Flutter - Cannot find package in .pub-cache reference

I am trying to use tflite_flutter plugin for running a custom ml function from a tflite model. It is working fine on android but for the iOS setup, it requires us to add TensorFlowLiteC.framework on ~/.pub-cache/hosted/pub.dartlang.org/tflite_flutter-<plugin-version>/ios/ folder but I cannot find this folder no matter what I do. It is not just because it is hidden, the tflite_flutter-<plugin-version> folder is not there at all.
I tried:
Adding dependency directly from git.
tflite_flutter:
git:
url: git://github.com/am15h/tflite_flutter_plugin.git
ref: v0.9.0
Running
flutter pub cache repair
flutter pub cache add tflite_flutter
Help would be much appreciated.
use_frameworks!
pod 'TensorFlowLiteSwift'
followed by running pod install in your ios folder.
From official doc
https://www.tensorflow.org/lite/guide/ios
As a developer, you are not bound to using flutter packages only. You can directly add dependencies to your podfile or build.gradle as well.
You'll find your package in ~/development/tools/flutter/.pub-cache/hosted/pub.dartlang.org/

How to use a specific version of flutter for build apk, when i have 2 version of flutter install?

So i am installing both version of flutter, version 2 and, 1.22.6 , i want to build apk for my 1.22.6 project, but flutter automatically call the version 2 for building apk, this create error, what should i do?
Try using this Flutter version manager
You can create alias for Flutter and point to different version
for example
flutter will call flutter 1.22.6
flutterd will call flutter 2 instead
so when you want to build for 1.22.6 just use flutter
I have write a article, sadly in Thai not translate yet, how to have 2 different version of Flutter and how to make alias to call different version here
https://medium.com/kbtg-life/%E0%B8%A3%E0%B8%B9%E0%B9%89%E0%B8%88%E0%B8%B1%E0%B8%81-flutter-2-0-%E0%B8%81%E0%B8%B1%E0%B8%99%E0%B8%A3%E0%B8%B6%E0%B8%A2%E0%B8%B1%E0%B8%87-%E0%B9%81%E0%B8%A5%E0%B9%89%E0%B8%A7%E0%B8%97%E0%B8%B3%E0%B8%A2%E0%B8%B1%E0%B8%87%E0%B9%84%E0%B8%87%E0%B9%83%E0%B8%AB%E0%B9%89%E0%B9%80%E0%B8%84%E0%B8%A3%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%87%E0%B9%80%E0%B8%A3%E0%B8%B2%E0%B8%A1%E0%B8%B5%E0%B8%97%E0%B8%B1%E0%B9%89%E0%B8%87-2-%E0%B9%80%E0%B8%A7%E0%B8%AD%E0%B8%A3%E0%B9%8C%E0%B8%8A%E0%B8%B1%E0%B8%99-de861c810d57?source=your_stories_page-------------------------------------
so after you this, you can just run
flutter build
I also faced same problem in the past. So what I did was, I downloaded both versions of flutter say (flutter2.2 and flutter1.22). And I have kept them in same folder. Now if I want to use flutter 2.2 then I'll rename "flutter2.2" folder to "flutter" and If I want to use flutter1.2 then I'll rename the "flutter1.2" folder to "flutter"
In the environment variable path I have set the path to "flutter/bin" so if I rename flutter2.2 to flutter then my environment variable will automatically take 2.2 version.
You may need to restart your PC after changing the version.
The simple way is:
Download the version of Flutter you need and put it in the place where Flutter is installed
In this directory you have "flutter" folder.
In Ubuntu, it is usually located in this path:
/home/username/development/flutter
To develop the software with the desired version, just change the desired folder name to "flutter".
For example :
flutter --> flutter-2.x.x
flutter-3.x.x ---> flutter

How to use a flutter plugin locally?

Let's say we have created a plugin with flutter. Named flutter_local_plugin.
How can we put it inside a flutter project flutter_some_application and access it?
There is a question here (how to use local flutter package in another flutter application?), but the accepted answer has 0 explanations regarding the actual file migrations.
we only need the plugin to be placed inside the flutter_some_application, without any example from the package project.
Where do you place the .kt & .dart files, and how do you link all of this together?
There seems to be no guide on how to achieve this.
I created a flutter plugin by Android Studio 4.0 which name is printer.
We can get a tip at the pubspec.yaml:
printer:
# When depending on this package from a real application you should use:
# printer: ^x.y.z
# See https://dart.dev/tools/pub/dependencies#version-constraints
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../
Then I use printer locally in another flutter project:
printer:
path: ../printer/
After pub get I found printer added in .flutter-plugins & .flutter-plugins-dependencies automatically.

How to test the working of flutter package?

What would be the best practice to test the working of flutter package?
Recently I developed a Flutter package and I am testing its functionality by creating another flutter application and importing it to there, in this way I have to deal with two projects. Is there any method to do all it in the same project like android native development?
example/ directory contains only example.dart which is not runable? Any suggestion ?
Answer based off of Shahzad's flutter_tex package, and thanks to Remi's suggestion.
As mentioned, one way to test a package in Flutter is to create a Flutter app within the "Example" directory. In this app, list the following in the pubspec.yaml file:
dependencies:
flutter:
sdk: flutter
your_package_name:
path: ../
As shown, you specify your package's path, which is the level above the "Example" folder the test app resides in.

How to obfuscate Flutter apps?

Flutter's wiki mentions obfuscation is an opt-in in release mode.
And yet, the flutter build command has no relevant option - see:
flutter help -v build apk
Am I missing something here?
Did they make obfuscation the default?
Is obfuscation even relevant for flutter?
Any pointers on this would be very appreciated.
Obfuscation is needed - a flutter app knows its function names, which can be shown using Dart's StackTrace class. There's under-tested support for obfuscation. To enable it:
For Android:
Add to the file [ProjectRoot]/android/gradle.properties :
extra-gen-snapshot-options=--obfuscate
For iOS:
First, edit [FlutterRoot]/packages/flutter_tools/bin/xcode_backend.sh:
Locate the build aot call, and add a flag to it,
${extra_gen_snapshot_options_or_none}
defined as:
local extra_gen_snapshot_options_or_none=""
if [[ -n "$EXTRA_GEN_SNAPSHOT_OPTIONS" ]]; then
extra_gen_snapshot_options_or_none="--extra-gen-snapshot-options=$EXTRA_GEN_SNAPSHOT_OPTIONS"
fi
To apply your changes, in [FlutterRoot], run
git commit -am "Enable obfuscation on iOS"
flutter
(Running "flutter" after the commit rebuilds flutter tools.)
Next, in your project, add following to [ProjectRoot]/ios/Flutter/Release.xcconfig file:
EXTRA_GEN_SNAPSHOT_OPTIONS=--obfuscate
PS: Haven't tried the --save-obfuscation-map flag mentioned at https://github.com/dart-lang/sdk/issues/30524
Again, obfuscation isn't very well tested, as mentioned by #mraleph.
AppBundle (recommended):
Without splitting:
flutter build appbundle --obfuscate --split-debug-info=/<directory>
Splitting:
flutter build appbundle --target-platform android-arm,android-arm64,android-x64 --obfuscate --split-debug-info=/<directory>
APK:
Without splitting:
flutter build apk --obfuscate --split-debug-info=/<directory>
Splitting:
flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi --obfuscate --split-debug-info=/<directory>
PS: About Splitting:
By default, fat apk contains arm v7, arm v8 and x64 which increases apk size, which you don't want to. So, when you split it, you have separate binaries which you can upload on the store and thus reducing the size of the apk that a user would need to download.
All the above answers are correct, but no answer tells you that we need to add a relative path or directory path while generating build.
Example using Relative Path:
flutter build apk --obfuscate --split-debug-info=./ProjectFolderName/debug
Example using Folder Path:
flutter build apk --obfuscate --split-debug-info=/Users/apple/Desktop/items/debug
The above command will generate a build inside the given project directory, it will create a new folder called ProjectFolderName or 'debug' on the respective command, and there you can find the release build.
https://flutter.dev/docs/deployment/obfuscateRefer this link for more info
Note: Flutter’s code obfuscation, Supported as of Flutter 1.16.2.
For Android the process is pretty clear from the doc at https://flutter.dev/docs/deployment/obfuscate. For Example:
export version=1.0.0
flutter build apk --release --shrink --obfuscate --split-debug-info=misc/mapping/${version}
Several files will be created such as misc/mapping/1.0.0/app.android-arm64.symbols (which you'll likely want to keep in VCS)
For iOS it's a bit less obvious since you often use the Xcode menu: Product > Archive
make an obfuscated build for iOS
flutter build ios --release --obfuscate --split-debug-info=misc/mapping/${version}
it creates file misc/mapping/1.0.0/app.ios-arm64.symbols
This will also modify ios/Flutter/Generated.xcconfig to include
DART_OBFUSCATION=true
SPLIT_DEBUG_INFO=misc/mapping/1.0.0
Use Xcode menu: Product > Archive which will uses Release.xcconfig which includes updated Generated.xcconfig
#include "Generated.xcconfig"
So your uploaded Archive will now be obfuscated (you don't need to make changes to Release.xcconfig)
See also - https://github.com/flutter/flutter/issues/64626#issuecomment-736081173
At the moment obfuscation is not directly exposed via the flutter CLI.
You can try to explicitly pass arguements to the gen_snapshot like this:
flutter build --extra-gen-snapshot-options=--obfuscate,--save-obfuscation-map=build/symbols.json --release
Note: that obfuscation support is not very well tested and might not work at the moment.
For iOS edit ios/Flutter/Release.xcconfig
This file should contain something like
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
If you check Generated.xcconfig there is a line DART_OBFUSCATION=false
So add opposite to the end of the Release.xcconfig file to override:
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
DART_OBFUSCATION=true
SPLIT_DEBUG_INFO=obj_maps
You can optionally add TREE_SHAKE_ICONS=true here to tree-shake icons as well