snapcraft build subdirectory - flutter

I have an flutter based application consisting of serveral "apps" that share some common source code. I tried to setup a snapcraft file for my application, but I can't figure out is make snap build a subdirectory.
This is an example layout that I have
appa/lib/main.dart
appb/lib/main.dart
packages/foundation
This is an example snapcraft file I have
parts:
appa:
source: .
source-type: local
plugin: flutter
flutter-target: lib/main.dart # The main entry-point file of the application
build-snaps: [ yq ]
override-build: |
cd appa
snapcraftctl build
snapcraftctl set-version "$(yq r pubspec.yaml version)"
In the above code I am sharing the the root directory . because otherwise I get an error that flutter cannot get ../packages/. When I build with the root directory I get an error that the working directory isn't a project root and flutter pub get fails.
Most examples I'm able to find online have a easier setup so haven't had any luck deriving a solution for this on my own. I am quite new snapcraft in general and terminology is a bit confusing to me. Would appreciate if somebody can point me in the right direction?

Related

Facing some issues while trying to Use DeepAR in Flutter

I have copied the deep.ar files in the locations they have mentioned
I am getting this error:
Could not determine the dependencies of task ':deepar_flutter:compileDebugAidl'.
> Could not resolve all task dependencies for configuration ':deepar_flutter:debugCompileClasspath'.
> Could not find :deepar:.
Required by:
project :deepar_flutter
Does anyone knows how to solve them?
I have tried these steps:
Run flutter clean
Delete pubspec.lock
Run flutter pub cache clean
Then try to do this:
You have to paste deepar.aar file into 2 different folders:
a. First In your flutter project as android/app/libs/deepar.aar.
b. Second ### %LOCALAPPDATA%\Pub\Cache\hosted\pub.dartlang.org\deepar_flutter-\android\libs\deepar.aar
But nothing the issues continues any know how to fix that please help me.
I am trying to use deep ar in flutter application but am getting errors.

How to "refresh" dependency packages with main project in Flutter?

I am new to flutter development. I am trying to separate my code into multiple local packages as dependencies. Here's my current project structure:
/packages/commons: a package containing common widgets & utility functions
/packages/fruits: a package containing screens about fruits (depends upon: commons)
/main: depends upon commons & fruits
Whenever I make a dependency-changeĀ¹ in commons package that affects fruits package, I have to execute flutter pub get in three folders(for commons, fruits and main-project) to be able to run code.
Is there any way to reduce this process to a single "refresh" click?
Example in commons:
flutter pub add fluro
flutter pub get
Since I was getting impatient, I thought of writing a small shell-script for this. I don't know if there is an easier way, but this worked for me.
My project has following folder structure:
project
pubspec.yaml
packages/
package1/
pubspec.yaml
package2/
pubspec.yaml
package3/
pubspec.yaml
I created a refresh.bash file in project folder. Here's how it looks like:
# open project directory or exit if failed
cd PROJECT_PATH || exit
# check if project contains pubspec.yaml file
if [ -f "pubspec.yaml" ]; then
# check if packages folder exists
if [ -d "packages" ]; then
# open packages folder
cd "packages" || exit
# run for all subdirectories of packages folder
for d in */; do
# open subdirectory
cd "$d" || exit
# check if subdirectory contains pubspec.yaml file
if [ -f "pubspec.yaml" ]; then
# run pub get for subdirectory (package)
flutter pub get
fi
# exit subdirectory
cd ..
done
# exit packages directory
cd ..
fi
# run pub get for project directory
flutter pub get
else
echo "pubspec.yaml not found"
fi
Replace PROJECT_PATH with path to your project.
To be able to run this script, I had to make it executable. This can be done with following command:
chmod +x refresh.bash
After this, I ran the script (in bash terminal) with:
./refresh.bash
Note: I don't know how shell-scripts work as well, I took some hints from a Shell Script Cheatsheet. So, if there are any issues, or if it can be smaller, please suggest me. This is my first day with shell-scripting.

I have issue when creating my first flutter app

After creating my app on flutter, I tried to create an app file from it ..
But I keep getting an error which says "flutter.bat failed to run. System cannot find the path specified at line1 char1"
I don't know if there's a solution to that.enter image description here
run flutter doctor -v and discard what it produces.
And try to fix your project, for this call
flutter create project_name for the folder where the root project is located.

How to obfuscate Flutter apps ios?

please help me for the steps to obfuscate the code, step by step until it's finished?
and how do I see if my obfuscate code is successful or not.
Previously I tried running this command "flutter build ios --obfuscate --split-debug-info = / / " but an error appears like this: bash: syntax error near unexpected token `newline ', why the error?
The "obfuscate" function will split the debug-info for your Flutter app when building for the respective platform. for e.g., if your preparing to ship the version 2.0.1, then you'll get a folder named "2.0.1" which shall contain the .symbols files.
Now about how to get this done is by using this command flutter build ios --obfuscate --split-debug-info=debug-info
This will create a folder named debug-info in the root directory of your project and if you do have a new directory created in that after running the above command, then it means that the obfuscation was successful.

How can I run an example from a Flutter package/library?

I have the following simple directory structure:
flutter_published
.idea
android
build
ios
lib
main.dart
flutter_published.iml
pubspec.lock
pubspec.yaml
network_to_file_image
.idea
example
main.dart
lib
network_to_file_image.dart
test
network_to_file_image.iml
pubspec.lock
pubspec.yaml
network_to_file_image is a package.
There are two main.dart files, one at flutter_published/lib/main.dart and
another at flutter_published/network_to_file_image/example/main.dart
I am able to run the first one, but not the one inside of the example directory under network_to_file_image. The second one gives me this error:
Launching example\lib\main.dart on Android SDK built for x86 in debug mode...
No application found for TargetPlatform.android_x86.
Is your project missing an android\AndroidManifest.xml?
Consider running "flutter create ." to create one.
Also, when the app is generated, what happens to the example and test directories of the packages I use? Are they included or removed from the final app that is deployed?
To solve this, instead of the main.dart file inside of the example directory, you need to create a complete Flutter application-type project inside of the example directory. Then, the example tab will point to the README.md file inside of that directory.
That example directory will have its own lib directory, containing a main.dart file. Since that file is now inside of an application-type directory it can be run.
Visit this repo to see how it works:
https://github.com/marcglasberg/async_redux/tree/master/example
Update:
To be clear, the example's pubspec.yaml file can reference its package by using a relative reference. For example, here is the dependencies section of the example dir of the async_redux package I mentioned:
dependencies:
http: ^0.13.1
async_redux:
path: ../
flutter:
sdk: flutter
Since the example dir is at the same level as the package's pubspec.yaml file, then the example's own pubspec.yaml is one level below it. Thus, it may reference the package itself by using a ../ path:
async_redux:
path: ../
example/main.dart only exists to be shown in https://pub.dartlang.org/packages/network_to_file_image#-example-tab-
The pub site is limited in how it finds content in the example directory to display in the Example tab.
cd to the directory and execute flutter create .. You should be able to run it afterwards
Go to the example folder of the repository of the package.
Open the lib folder and go to the main.dart file.
Above the void main() function, you can see the Run|Debug|Profile (pic below), click on the one you want to run the project as.
The example app will now run in your emulator.
The screenshot below is of the chewie package available on pub.dev