Cross-platform development has become the standard for creating mobile applications that work equally well on both Flutter has become the standard for creating mobile applications that work equally well on Android and iOS. However, many developers encounter difficulties already at the stage of setting up the environment - especially when it comes to integration Flutter SDK c Android Studio. This article will not only tell you how to add Flutter to Android Studio, but also explain why each step is important, what pitfalls can arise, and how to avoid them.
If you are switching from native development to Kotlin/Java or are just starting out in mobile development, this guide will help save you hours of searching for solutions to common mistakes. We will consider not only the basic installation, but also optimization Android Studio for working with Flutter, setting up emulators, and even the nuances of working with pubspec.yaml. And at the end - answers to the most common questions that beginners have.
1. Checking system requirements before installing Flutter
Before downloading Flutter SDK, make sure your system meets the minimum requirements. This will eliminate errors at the installation stage and save time.
To work with Flutter v Android Studio you need:
- ๐ฅ๏ธ Operating system: Windows 10/11 (64-bit), macOS (x86_64 or ARM), or Linux (64-bit). Support Windows 7/8 officially discontinued.
- ๐พ Free disk space: no less
2.8 GB(excluding Android SDK i emulators). Recommended10+ GBfor comfortable work. - ๐ง Development tools: Git (for version control), Android Studio 2022.3+ (or IntelliJ IDEA with plugins).
- ๐ฑ Device for testing: physical Android smartphone with software debugging enabled
USBor emulator (Android Virtual Device).
Flutter does not support 32-bit systems and virtual machines without hardware acceleration (for example, VirtualBox without Hyper-V enabled). If you use macOS on Apple Silicon (M1/M2), you will need additional configuration to work with Android Emulator.
โ ๏ธ Attention: Hardware and software requirements may change with the release of new versions FlutterBefore installation, check the current conditions on official website.
2. Installing the Flutter SDK: step-by-step guide
Downloading and installing Flutter SDK โthe first critical stage. Errors here will lead to problems with dependencies and building projects.
Follow this algorithm:
- Download the archive from the Flutter SDK s official website. Select the version for your OS (stable channel recommended for beginners).
- Unpack the archive to a folder without spaces and Cyrillic characters in the path (for example,
C:\src\flutteror/Users/yourname/development/flutter). - Add Flutter to the environment variable
PATH:- ๐ช Windows:
Control Panel โ System โ Advanced system settings โ Environment variablesโ add the path toflutter\bin. - ๐ macOS/Linux: add a line to
~/.bashrcor~/.zshrc:export PATH="$PATH:[PATH_TO_FLUTTER]/flutter/bin"
- ๐ช Windows:
flutter doctor
It will show which components are configured correctly and which require attention.
If flutter doctor produces errors related to Android Licensefollow:
flutter doctor --android-licenses
and agree to all license agreements (click y for each item).
โ๏ธ Checking Flutter installation
3. Setting up Android Studio to work with Flutter
Android Studio is the main tool for development on Flutter, but by default it is not configured to work with it framework. You will need:
Install plugins:
- Open Android Studio โ go to
File โ Settings โ Plugins(orAndroid Studio โ Preferences โ Pluginsto macOS). - Find and install two plugins:
- ๐ง Flutter โthe main plugin to support the framework.
- ๐ฑ Dart โthe programming language in which Flutter applications are written.
Create a new Flutter project:
- In the start window, select
New Flutter Project. - Specify the project type - for example,
Flutter Application. - Specify the project name (without spaces or special characters), the path to save and click
Finish. - ๐ Is the path to correct? data-i="130">in settings Flutter SDK in settings Android Studio (
File โ Settings โ Languages & Frameworks โ Flutter). - ๐ Restart Android Studio after changing the path.
If an error occurs when creating a project "Flutter SDK not found", check:
If Android Studio takes a long time to index the project after creation, open File โ Invalidate Caches / Restart โthis will speed up the process.
4. Setting up an Android emulator for testing Flutter applications
Without an emulator or a physical device, you will not be able to test your application. Flutter requires Android Emulator with support x86_64 or ARM.
How to create a virtual device:
- Open
AVD Managerto Android Studio (icon in the form of a phone with a plus). - Click
Create Virtual Deviceโ select a model (for example, Pixel 5). - Download the system image (Android 13+ recommended for the latest versions Flutter).
- Configure the emulator parameters:
- ๐ฅ๏ธ RAM: minimum
2 GB(optimally4 GB). - ๐พ Internal Storage:
8 GBis enough for most projects. - ๐ Graphics:
Hardware - GLES 2.0for better performance.
- ๐ฅ๏ธ RAM: minimum
Common problems with the emulator and their solutions:
| Problem | Cause | Solution |
|---|---|---|
| The emulator does not start | Not enough memory or hardware acceleration is not enabled | Increase RAM in the AVD settings or enable Hyper-V (Windows)/HAXM (macOS) |
| The application does not install on the emulator | Incompatible version Android or Flutter SDK | Update Flutter (flutter upgrade) or create an AVD with a newer version Android |
| The emulator is slow | Low PC performance or turned on Software Rendering |
Use Hardware Acceleration and close other resource-intensive apps |
โ ๏ธ Attention: On macOS with Apple Silicon chip (M1/M2) standard Android Emulator does not work. Use alternatives: Android Studio Arctic Fox+ with support for ARMemulators or a physical device.
5. First launch of a Flutter project: debugging and common errors
After setting up the environment, the moment of truth has come - launching the first project. Even if everything is configured correctly, unexpected errors may occur.
How to run the project:
- Open the file
main.dartin Android Studio. - Select the target device (emulator or physical) in the top panel.
- Press the green button
Run(orShift + F10). - ๐จ
"No devices available":- Check if the emulator is running (
AVD Manager). - For a physical device, enable
USB DebugginginSettings โ For developers.
- Check if the emulator is running (
- ๐จ
"Flutter plugin not installed":- Reinstall the plugins Flutter in Dart in Android Studio.
- Check that the path to Flutter SDK specified correctly in the settings.
- ๐จ
"Gradle build failed":- Update
Gradlein the fileandroid/gradle/wrapper/gradle-wrapper.properties(the current version is indicated in Gradle documentation). - Run
flutter cleanand rebuild the project.
- Update
- ๐ Correctness of the code in
main.dart(there must be a widgetMaterialApp). - ๐ Logs in the console Android Studio (
Run โ Debug). - โก Enable
Hot Reload:- Keyboard shortcut:
Ctrl + S(save) +Rin the terminal console. - Or button
Hot Reloadin the top panel (icon with lightning).
- Keyboard shortcut:
- ๐ Configure
Dart Analysis:- Go to
File โ Settings โ Editor โ Inspections. - Disable unnecessary warnings (for example,
"Unused import"for test files).
- Go to
- ๐ Use
.gitignore:- Add to the file:
/.dart_tool//build/
/android/.gradle/
/android/local.properties
- Add to the file:
- ๐ง Enlarge
Heap SizetoHelp โ Edit Custom VM Options(add line-Xmx4G). - ๐๏ธ Clear cache once a week (
File โ Invalidate Caches). - ๐ Versioning:
- Use
^1.2.3to automatically update minor versions. - For stability, fix versions without
^(for example,1.2.3).
- Use
- ๐ Update dependencies:
- Run
flutter pub outdatedto check for outdated packages. - Update dependencies with command
flutter pub upgrade.
- Run
- ๐ซ Dependency conflicts:
- If two packages require different versions of the same library, use
dependency_overrides(carefully!).
- If two packages require different versions of the same library, use
- ๐จ
"Because every version of package X depends on Y, which doesn't match...":How to resolve the conflict dependencies?
Use the command
flutter pub deps --style=compactto see the chain of dependencies. Then add thepubspec.yamlblockdependency_overridesblock with the desired package version. For example:
Attention: This is a temporary solution! Update the main dependencies as soon as possible.dependency_overrides:shared_preferences: 2.0.15 - ๐จ
"Target of URI doesn't exist: 'package:...":- Do
flutter pub get. - Check for typos in the package name.
- Do
- ๐ Syntax highlighting and code completion.
- ๐ Built-in debugger and
Hot Reload. - ๐ฆ Management dependencies through the interface Android Studio.
Typical errors and their solutions:
If the application starts but displays a white screen, check:
If the project is not built, always run flutter clean i first - this solves 80% of dependency problems. flutter pub get - this solves 80% of dependency problems.
6. Optimizing Android Studio for convenient work with Flutter
By default Android Studio is not optimized for Flutter. Several settings will significantly speed up development:
Useful settings:
Recommended plugins for Flutter development:
| Plugin | Purpose | Installation link |
|---|---|---|
| Flutter Intl | Automatic generation of localizations (i18n) | Marketplace in Android Studio |
| Dart Data Class Generator | Generation of class templates using JSON | Marketplace in Android Studio |
| Rainbow CSV | Color marking CSVfiles (useful for data) |
Marketplace in Android Studio |
If Android Studio slows down when working with large Flutterprojects, try:
7. Working with dependencies: pubspec.yaml and common errors
The file is the heart of any project. Dependencies ( pubspec.yaml - anyone's heart Flutter-project. Dependencies are indicated here (packages), resources and application settings are indicated here. Errors in this file are one of the main reasons for build failures.
Basic rules of operation. with pubspec.yaml:
Example of correct pubspec.yaml:
name: my_appdescription: A new Flutter project
version: 1.0.0+1
environment:
sdk: ">=2.19.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
http: 0.13.5 # Fixed version for stability
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
Frequent errors and solutions:
โ ๏ธ Attention: Never commit a folder to the repository.pub-cacheโit takes up gigabytes and contains temporary files. Add it to.gitignore.
FAQ: Answers to frequently asked questions
Is it possible to use Flutter in Android Studio without plugins?
Technically yes, but it is extremely inconvenient. Without plugins Flutter and Dart you will lose:
Plugins take up less 50 MB and significantly speed up development.
How to update Flutter to the latest version?
Execute in the terminal:
flutter upgrade
If you need to switch to another channel (for example, beta):
flutter channel beta
flutter upgrade
After the update, restart Android Studio and run flutter doctor.
Why does the emulator not see the physical device?
Check:
- Enabled whether
USB Debuggingon the phone (Settings โ For developers). - Are drivers installed for your device (especially important for Windows).
- Is the phone connected in mode
Transfer files(notOnly charging). - Has the command been executed
adb devicesin the terminal (the serial number of the device should be displayed).
If the device is still not detected, try:
adb kill-server
adb start-server
How to speed up the build of a Flutter project?
Here are several ways:
- ๐ฅ Use
--releaseonly for the final build:flutter run --release - ๐๏ธ Clear the cache before building:
flutter clean - ๐ ๏ธ Disable unnecessary plugins in
pubspec.yaml(especially in mode development). - ๐ฅ๏ธ Increase memory for
Gradlevandroid/gradle.properties:org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=1G
Is it possible to develop on Flutter without Android Studio?
Yes, but with limitations:
- ๐ป VS Code +. extensions Flutter i Dart โa light and fast environment, but without a built-in emulator.
- ๐ฑ IntelliJ IDEA โsimilar to Android Studio, but without specialized tools for Android.
- ๐ง Terminal โyou can write code in any editor and run command
flutter runmanually.
However, for full development under Android Android Studio remains the best choice due to integration with AVD i Gradle.