What is the Android Debug Bridge (adb) ?
ADB (Android Debug Bridge) is a command-line tool included with the Android SDK (Software Development Kit) and is used in Flutter development for interacting with Android devices or emulators. It allows developers to perform various debugging tasks, install and uninstall apps, and manage device communication.
Running a Flutter app without connecting via USB using ADB (Android Debug Bridge) involves setting up a wireless connection for your device and then using ADB commands to install and run the app.
Note: Please note that the initial setup requires a one-time USB connection. Here’s a step-by-step guide:
Before using ADB in the terminal, add the ADB executable to the system path:
ADB installation or setup:
To verify that ADB is set correctly, open a command prompt or terminal window and run the following command:
adb version
You should see information about the ADB version if the installation is successful. If you get this error (‘adb’ is not recognized as an internal or external command, operable program, or batch file), to solve this error, here are the additional steps to add ADB to the system path:
Setting up ADB path on Windows:
- Locate the ADB executable:
- Find the location where ADB is installed on your system. This is usually in the “platform-tools” directory within the Android SDK installation, for example, C:\Users\Xman\AppData\Local\Android\Sdk\platform-tools.
- Copy the ADB path:
- Copy the path to the directory containing the ADB executable.
- Add ADB to the system path:
- Right-click on “This PC” or “Computer” on your desktop or in File Explorer and select “Properties.”
- Click on “Advanced system settings” on the left.
- Click on the “Environment Variables” button.
- In the “System variables” section, find and select the “Path” variable, then click on “Edit.”
- Click on “New” and paste the path to the ADB directory.
- Click “OK” to close each dialog box.
- Verify the setup:
Open a new command prompt and run the following command to verify that ADB is now in the system path:
adb version
Initial Setup:
1. Connect your device via USB:
- Connect your Android device to your computer using a USB cable.
- Open a terminal and run the following command to check if your device is recognized by ADB:
adb devices
2. Enable USB debugging on your Android device.
- Open device “Settings,” tap “About phone,” and tap “Build number” seven times.
- In “Developer options,” toggle “USB debugging” to enable it.
3. Find your device’s IP address:
Ensure that your device and your computer are connected to the same Wi-Fi network. Open terminal and run this command in terminal or command prompt
adb shell ip route
Here are the additional steps to add ADB to the system path:
adb version
Wireless Setup:
1. Connect via ADB over Wi-Fi:
Run the following command to connect your device to ADB wirelessly using the IP address obtained:
adb tcpip 5555
2. Disconnect USB:
After running the command, you can disconnect the USB cable from your device.
3. Reconnect wirelessly:
Run the following command to connect to your device wirelessly:
adb connect DEVICE_IP_ADDRESS:5555
Replace DEVICE_IP_ADDRESS with the IP address you obtained in step 2.
Run the Flutter app:
1. Navigate to Flutter Project:
Open a terminal and navigate to your Flutter project directory.
2. Install and run the App:
Run the following commands to install and run your Flutter app on the connected device wirelessly:
bash
flutter run
If you have multiple devices, you can specify the device using the -d flag. you can run the following command For example:
flutter run -d DEVICE_IP_ADDRESS:5555
Develop and Test:
You can now develop and test your Flutter app wirelessly.
Additional Tips:
If you encounter issues, you may need to restart the ADB server by running:
adb kill-server
adb start-server
Ensure that your firewall allows ADB connections.