Flutter emulator APK contains all ABIs - flutter

I am having a project with a lot of native .so files for different ABIs.
When I am launching the Flutter Android emulator from Visual Code, it takes ages to build and install the app.
I checked the apk and it contains all the .so files for all the ABIs.
Is it possible to tell Flutter to only target the emulator ABI?

flutter run does not support specifying a target platform, however it supports passing a flavour. We can use that to workaround the problem.
Create a flavour for the emulator that filters the ABIs:
flavorDimensions "abi"
productFlavors {
emulator {
dimension "abi"
ndk {
abiFilter "x86_64"
}
}
all {
dimension "abi"
}
}
Now, by calling flutter run --flavor emulator, the APK will only contain the x86_64 native libraries.
For Visual Code, the .vscode/launch.json can be amended to pass the flavour:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Flutter",
"request": "launch",
"type": "dart",
"args": [
"--flavor",
"emulator"
]
}
]
}

Related

Setup launch.json file for Flutter web using local Flutter version

I have installed Flutter in my mac inside my root folder: /[root]/flutter and I use it on project A.
Now I need to use a different version of Flutter for project B (flutter web), so I cloned Flutter inside project B's root directory.
I know that to run it, I have to launch ./flutter/bin/flutter run but how can I setup launch.json for VScode?
Here is my launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": "Web",
"type": "dart",
"request": "launch",
"deviceId": "chrome",
"args": [
??
]
},
]
}
I think that if I use it, then it will use the standard Flutter in my mac root and not the Flutter inside the project folder.
How can I edit the launch in a way that if I click on the play button in VScode then it will run ./flutter/bin/flutter run?
I'm not interested to use tools like FVM
Open command palette, enter Preferences: Open User Settings.
Search Flutter Sdk Paths. Add additional flutter sdk from there.
Open flutter project. Do Flutter: Change SDK in the command palette.

vscode not select correct dart sdk

I have download different dart sdk and wish to switch sdk for different flutter project. In vscode I have add two downloaded dart sdk path into settings, and use Ctrl+Shift+P to change dart sdk location path, I selected Dart SDK 2.7.0 but vscode keep pointing back to the old dart sdk location (image below with Current setting)
Found a solution, inside root project folder create .vscode folder if don't have.
Next create settings.json if don't have. Paste the json below to overwrite current project sdk path. Remember to replace to your own sdk path
{
"dart.flutterSdkPath": "C:\\flutter_1.22.6",
"dart.sdkPath": "C:\\dart\\dart-sdk_2.7.0"
}
No need to change sdk path by using Ctrl+Shift+P each time.
Tip here, if facing any pub cache issue while building, just flutter clean and flutter pub get again
You can try this, and create a launch.json, by going to Run in VScode menu, then Add Configurations,
Add the following, mind you, your project's directories.
{
"configurations": [
{
"program": "lib/main.dart",
"name": "YOUR APP NAME",
"cwd": "/home/u/Projects/fireflutter/live-projects/YOUR_PROJECT_FOLDER/",
"type": "dart",
"request": "launch",
"flutterMode": "debug",
"args": [
// "--web-port",
// "8080",
// "--no-sound-null-safety",
// pass your arguments here, whatever you would type
//in the terminal when you would use i.e
//flutter run --no-sound-null-safety[I love null safety by the way,
//but this is a common problem for people who still want to opt out of it.
],
}
],
"dart.flutterSdkPath": "/home/u/Downloads/sdks/flutter",
"dart.sdkPath": "/home/u/Downloads/sdks/flutter/bin/dart",
}

Can't launch my flutter app with VScode and Android Studio Emulator

I can't launch my flutter app, this is the message I get when I try to run with debbug and without debbug mode:
Your launch config references a program that does not exist. If you have problems launching, check the "program" field in your ".vscode/launch.json" file.
My .json file by default:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Dart",
"program": "lib/main.dart",
"request": "launch",
"type": "dart"
}
]
I run flutter doctor:
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[√] Android Studio (version 3.6)
[√] VS Code (version 1.46.1)
[√] Connected device (1 available)
! Doctor found issues in 1 category.
And accepted all the licenses.
Thank you.
Consider these two:
1. Make sure that you opened the root of the project, not a folder higher. So that .vscode folder will be created on the same level as lib folder.
2. Check that lib/main.dart exists. If your main function is different, edit the launch.json file and change the program.
delete your launch.json file and then open your debug menu and click on create a launch.json file
From the dropdown, select dart and Flutter and run the app again
if you are facing this problem kindly check the following steps
Try to give a perfect path to your main.dart file in flutter app from launch.json file
eg.
{
"version": "0.2.0",
"configurations": [
{
"name": "Dart",
"program": "shop_app/lib/main.dart",
"request": "launch",
"type": "dart"
}
]
}
if it does not work then from the terminal type
flutter clean
flutter run
Make sure the configurations program path is the same path of your main.dart or wherever your main method is.
void main() {
runApp(MyApp());
}
This works for me.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Dart & Flutter",
"request": "launch",
"type": "dart",
"program": "lib/main.dart"
}
]
}
Adding the correct root folder as cwd to the launch config fixed it for me.
"configurations": [
{
"name": "Flutter",
"type": "dart",
"request": "launch",
"program": "lib/main.dart",
"cwd": "${workspaceFolder}"
}
]
Pretty sure this was not the answer when the question was asked, but I got the same error message apparently after a recent update of the flutter extension in VS Code.
It looks like they changed how the working directory is deduced if not specified: https://dartcode.org/releases/v3-50/
Better add the complete path and it worked for me. This has occurred since I have moved my main. dart file from lib to new folder widgets. once I gave the complete path it worked.
"configurations": [
{
"name": "exp_app",
"request": "launch",
"type": "dart",
"program": "E:\\FLUTTER\\exp_app\\lib\\widgets\\main.dart"
}
]

flutter new web project not showing in Android emulator

I am new with Flutter, and I am trying to view my new project with Android Emulator. I've installed Dart, Flutter, and Android Studio correctly, but when I try to start the project in Visual Studio (without and with debugging mode), and choosing the correct emulator I get the following error:
Your launch config references a program that does not exist. If you
have problems launching, check the "program" field in your
".vscode/launch.json" file.
I have read in the documentation that it is possible to fix this by adding:
"program": "lib/main.dart",
instead of:
program : bin/main.dart
But still does not work.
First of all, your question says you are going to run Flutter web project in android emulator.
From this, I am guessing that you are using Flutter beta version. With that version, you can't run your project on android emulator.
Second, to run Flutter project on VSCode, you need to add launch.json file for some configuration like this.
{
"version": "0.2.0",
"configurations": [
{
"name": "Flutter - Current",
"request": "launch",
"type": "dart"
}
]
}

Unable to debug flutter dart code in VS Code, Unverified Breakpoint error

When the code is not running, I can add breakpoint (round red circle), but as soon as it goes into debug mode, it turns into unverified breakpoint (grey hollow circle) and doesn't work at all. However, the same project works well on other systems.
I've no idea what the problem is or what the solution would be.
I've tried reinstalling flutter SDK numerous times, and have gone through a lot of links on SOF and GitHub regarding this, but none has been helpful enough.
Environment - VS Code,
Flutter version: 1.17.2
Flutter doctor -
[✓] Flutter (Channel stable, v1.17.2, on Mac OS X 10.15.3 19D76, locale en-GB)
[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, set ANDROID_SDK_ROOT to that location.
You may also want to add it to your PATH environment variable.
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
[!] Android Studio (not installed)
[✓] VS Code (version 1.45.1)
[✓] Connected device (1 available)
! Doctor found issues in 2 categories.
My launch.json File -
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Flutter: Run all Tests",
"type": "dart",
"request": "launch",
"program": "./test/"
},
{
"name": "Dart: Run all Tests",
"type": "dart",
"request": "launch",
"program": "./test/"
},
{
"name": "Dart",
"type": "dart",
"request": "launch",
"program": "bin/main.dart"
},
{
"name": "Dart: Attach to Process",
"type": "dart",
"request": "attach"
},
{
"name": "Flutter",
"request": "launch",
"type": "dart"
}
]
}
Also, If you know any good alternatives to VSCode and Android Studio for Flutter, please share.
i came from mac and always use fn + f5, on windows that means start withouth debugggin, that was my mistake.
"version": "0.2.0",
"configurations": [
{
"name": "Flutter",
"request": "launch",
"type": "dart",
"flutterMode": "debug"
}
]
}
This is my launch.json file ... changing "flutterMode" from profile to debug solved the issue ... if you dont have this line adding it could help.
For anybody running into this problem while trying to debug external libraries or sdk code: Make sure you checked "Dart: Debug External Libraries" and "Dart: Debug Sdk Libraries" under Settings > Extensions > Dart & Flutter as described here.
You can also add the following to your settings.json
"dart.debugExternalLibraries": true,
"dart.debugSdkLibraries": true,
Clicking Run on the top menu in VS code and selecting 'Enable all breakpoints' worked for me. Though you have to place your breakpoint first.
You can also try placing your breakpoint and save your code, then leave the emulator running and close and restart your vs code IDE and run the app with debugging.
For flutter-web I had to change back to <base href="/"> within the web/index.html. A custom href lead to a none-debuggable project.
Navigate to the Run Tab and select Dart & Flutter from the drop down menu, finally hit the play button.
Your main.dart file's path is not specified right.
so in this block
"name": "Dart",
"type": "dart",
"request": "launch",
"program": "bin/main.dart"
please use
"program": "lib/main.dart"
I was also facing the same issue, I am looking for the exact reason but removing the launch.json file worked for me.
Have faced the same issue, resolved by stopping the current active session and click on RUN and select START DEBUGGING. This worked for me.
I faced the same problem with debug in certain dart files, but the other files I could.
Then I realized that it happened when I call another file and this trick would help:
Instead of typing:
import '../form/productdetail.dart';
I replaced with:
import 'package:myapp/form/productdetail.dart';
and it helped.
I had a similar problem. I solved by completely uninstalling and reinstalling Vscode + remove the data. See here
In my case, the parents folder contains special character (#):
.../#Projects/my_project/
Remove the # and the debug goes well:
.../Projects/my_project/
I had a similar problem. My platform is Ubuntu 20.04. I was setting the breakpoint in vscode expecting the vscode debugger to work immediately, but no. After an hour of googling, I hit the Flutter docs on the DevTools page.
To resolve :
Open your flutter project in vscode.
Follow the 'Install from VS Code' section of the docs to install DevTools.
Start your emulator, wait for it to completely load up.
Select Run => Start Debugging.
Check that app is running as expected in the emulator.
Select commandPalette => Dart:Open DevTools => 'Open DevTools in web browser'. The DevTools dashboard opens in a new browser tab.
Select the Debugger tab.
Open the relevent code file and add your breakpoint by clicking the leftmost breakpoint column at the required line.
Progress your app by clicking the emulator UI. Vscode debugger should stop at your breakpoint.
Use the vscode debugging controls thereafter.
Try to rebuild your launch.json file.
Remove the old file from the .vscode directory in vscode, then goto Run and Debug window and create a new launch file.