Flutter - Target file "–flavor" not found - flutter

I'm following this tutorial to manage different Firebase environments.
However, when trying to run the app with a specific flavor, it doesn't work.
I do :
flutter run -flavor dev
or:
flutter run --flavor dev
But I get this error message:
Target file "–flavor" not found.
Here is the relevant part of my
flavorDimensions "default"
productFlavors {
dev {
dimension "default"
applicationIdSuffix ".dev"
}
tst {
dimension "default"
applicationIdSuffix ".tst"
}
prd {
dimension "default"
}
}
Sadly, I cannot find anything related to my issue on the internet.
EDIT: I don't know what kind of black magic it is, but after doing
flutter run -h
Then
flutter run --flavor dev
It worked... Time to go to sleep

The reason why you're getting the error initially is that you're running flutter run -flavor dev - flavor needs to be --flavor. On the other hand, running flutter run -h unlikely helps since it just prints out the usage information for flutter run. Setting up flavors in Android, the config should be set in the Android build's app/build.gradle as mentioned in this guide. Separate steps are needed if you'd like to configure one for iOS as well.

Related

How to debug what's wrong if app crashes only in release mode

I upgraded Flutter to 2.0.0 recently and am stuck with this issue. flutter run and flutter run --profile work perfectly well, but flutter run --release makes app crash after startup. There is no stacktrace, there is no error or warning, there is no build issue or verbose warning, no hint really. I googled a lot, but similar questions were answered like "try to remove this line" or "try to add that line". I couldn't find any clear steps on how to debug what's wrong.
What steps should I take to debug this issue and find the root cause instead of trying meaningless changes on code hoping some of them will eventually fix the issue?
Use adb logcat
OR
Enable debugging in release build, by modifying your android/app/build.gradle
like this
buildTypes {
release {
debuggable true
shrinkResources false
minifyEnabled false
...
}
}
When the error is code related and not in flutter itself sentry should help.
Sentry's Flutter SDK enables automatic reporting of errors, messages,
and exceptions.
You can import it just as any other package
dependencies:
sentry_flutter: ^4.0.6
and configure it as early as possible in you app
import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
await SentryFlutter.init(
(options) => options.dsn = 'put_your_public_key_here',
appRunner: () => runApp(MyApp()),
);
}
To get your public key you just have to sign up on sentry.io and create a flutter project, no need to search for your key your it should be in the example code, it wont let you pass that point without initialiting it so you can't miss it.
The docs regarding flutter can be found here.
You can Use Firebase Analytics to see error logs from your released devices from firebase. Previously it was named as Fabric.
Or you can create your own log tracker, write the logs in a file and upload the log to your server.
You can give options to user to capture log and send to server within "Advanced Settings" or something like that.
try this flutter run --release --no-shrink
Check if you have given correct permission to the app in AndroidManifest.xml, in my case I simply fixed this issue by giving camera permission
<uses-permission android:name="android.permission.CAMERA" />
before the tag
In my case, after two day of confusion because app crashes only in release mode without any error on console, and errors shown in adb logcat not clear (unknown errors), after that I switching Flutter channel from stable to master, after run release on master channel errors started shown as clear messages, I solved these errors then crashes problem solved.
So my steps is:
1- Switching Flutter channel to master by run this command in terminal:
flutter channel master
2- Run upgrade command in terminal:
flutter upgrade
3- Run app as release:
flutter run --release
4- Watch console to see errors...

Exception: Unsupported Android Plugin version: 4.1.2

I know this might have been asked before, I have recently installed Solus Linux on my computer and I am trying to get Andoird Studio working on it for some time, so far I am not having any luck.
First Issue - I am not able to add Flutter to the PATH
Second Issue - I am getting this error when running the project
Could somebody here help me with both issues?
Maybe it can help future devs. I had similar problem with the exception
Unsupported Android Plugin version 4.1.3
In my case I had to specify build flavor for the app:
flutter run --flavor <flavor-name>
then it worked
I think at the moment, there is a problem of incompatible version.
Reference: from this thread
To fix it, I revert back Android Plugin from 4.1.2 to 4.1.0.
Modify the root build.gradle:
buildscript {
ext.kotlin_version = '1.4.20'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
...
}
}
Note: I, currently, use Gradle 6.7
Doing this solved my problem
Added dev as Build flavor
Added --debug as Additional build args
In my case, I had to edit my configuration settings:
go to "Edit configurations"
choose the config you're trying to run
fill in the "Build flavor" accordingly
Worked for me
if your are performing integration test in flutter with flavors then you should run this command to test
flutter drive --flavor dev \ --driver=test_driver/integration_driver.dart \ --target=integration_test/login_page/login_integration_test.dart
For me, it was about the flavor configuration. I have main, develop, and production flavors I haven't set up configuration for main so when main is selected this error is happened
In my case, I solved it by changing the "splits" property to enable = false, in the build.gradle. When we release to production that property is set to true, so i just forgot to set it on false again.
Should be something like this:
splits {
// Configures multiple APKs based on ABI.
abi {
// Enables building multiple APKs per ABI.
enable false
// Resets the list of ABIs that Gradle should create APKs for to none.
reset()
// Specifies a list of ABIs that Gradle should create APKs for.
include 'arm64-v8a', 'armeabi-v7a'
// Specifies that we do not want to also generate a universal APK that includes all ABIs.
universalApk false
}
}

Flutter Gradle build with error exception

i just setup my android studio and vs code and flutter SDK installed but any time i try running the project i get this Gradle error, i cant figure out what the problem is please help me out.
After running the flutter doctor everything seems to be okay.
the problem might be caused by many factors so lets try some solutions
after each one rebuild your app if the error message changed or the problem solved please keep us informed
run these commands one by one
flutter channel stable
flutter upgrade --force
flutter pub cache repair
cd your app folder
flutter clean
edit app/build.gradle in your host app such as it includes the local repo
like in here
repositories {
maven {
url 'https://storage.googleapis.com/download.flutter.io'
}
}
use VPN and rebuild your app

How to do integration testing in Flutter?

I want to do integration testing in Flutter. The tutorial I follow gives the following procedure:
Add the flutter_driver package to pubspec:
dev_dependencies:
flutter_driver:
sdk: flutter
Enable the Flutter driver extension and add a call to
the enableFlutterDriverExtension() function in main.dart.
Run the integration test by using the flutter drive command:
flutter drive --target=my_app/test_driver/my_test.dart
My problem is with understanding step 2. It's not clear to me where in Android Studio do you enable the driver extension and where exactly in main.dart do you call the function enableFlutterDriveExtension().
I also have problems with the third step. After running the said command, it says in my terminal that
Error: The Flutter directory is not a clone of the GitHub project.
The flutter tool requires Git in order to operate properly;
to set up Flutter, run the following command:
git clone -b stable https://github.com/flutter/flutter.git
You have to add this code inside the test_driver/app.dart file.
import 'package:flutter_driver/driver_extension.dart';
import 'package:[YOUR_APP]/main.dart' as app;
void main() {
// This line enables the extension
enableFlutterDriverExtension();
// Call the `main()` function of your app or call `runApp` with any widget you
// are interested in testing.
app.main();
}
You can find more info on the official Flutter documentation site (Steps 3 & 4):
https://flutter.dev/docs/cookbook/testing/integration/introduction
Good luck ;)
In order to run integration test in flutter, you need to create "test_driver" directory inside app root dir. Than you need to create two files inside "test_driver" folder.
Lets call first file "app.dart" and there you need to instrument your app(answer above).
Than you need to create your test file, which needs to be called "app_test.dart" and here you write your actual test code.
When you want to run that test, just run "flutter drive --target=test_driver/app.dart".
About step 3 in your question, check if you set flutter home properly and after adding flutter_driver dependency, run "packages get".

new flutter project in vscode has error

when i create a new flutter project in vscode it will immediately shows an error in the main.dart file and gives a gradle error when trying to debug.
shown here: main.dart error
"compiler message: lib/main.dart:68:19: Error: Too few positional arguments: 1 required, 0 given."
I've reinstalled dart and flutter plugins. updated the java install.
in debug console i get this:
debug console
added output of flutter doctor -v
enter image description here
I was also facing the same error, but it was always on my test folder.
This is what I did:
On your terminal, make sure you are in your project repository.
Run the flutter pub get command, it worked for me, may be you
should try it too.
Do you possibly have two different versions of the Flutter SDK on your machine? I wonder if one is being used by flutter create and the other for analysis.
If you're sure you only have one, please open an issue on GitHub and attach a log file for me to investigate.