Arch: Flutter Dev (Android Dev)
Setup Flutter for Android Development (Flutter + Android SDK Cmdline + ADB + Waydroid)
DISCLAIMER
THE WIKI IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE WIKI OR THE USE OR OTHER DEALINGS IN THE WIKI.
Install the android sdk packages
We will be installing android sdk without the studio, you can install studio if you like it better. You can do flutter dev with some other editor other than android studio, you don't need to install the full studio for development.
Install from aur using aur helpers like yay:
yay -Syy android-platform android-sdk-build-tools android-sdk-cmdline-tools-latest android-tools
Alternatively, you can install from chaotic aur if you have the repo enabled:
sudo pacman -Syy android-platform android-sdk-build-tools android-sdk-cmdline-tools-latest android-tools
While installing please select jdk17-openjdk when prompted. I have tested it to work fine with that. It may not work with newer jdk releases based on the version of gradle you are using. Check gradle-java-version-compatibilty
change ownership of android sdk folder to user for read write access:
sudo chown $USER /opt/android-sdk
Add SDK Manager to PATH
Add sdk manager to path in .bashrc or symlink it to /usr/bin/sdkmanager:
sudo ln -s /opt/android-sdk/cmdline-tools/latest/bin/sdkmanager /usr/bin/
Install SDK for Android platform version
sdkmanager --install "platforms;android-34" "build-tools;34.0.0"
Install Flutter
Install flutter from aur using yay:
yay -Syy flutter
Alternatively install flutter from chaotic aur if you have it enabled:
sudo pacman -Syy flutter
change ownership of flutter folder to user for read write access:
sudo chown $USER /opt/flutter
Add Flutter to PATH
Add dart to path for it to be accessible from terminal using bashrc or symlink it to /usr/bin/dart:
sudo ln -s /opt/flutter/bin/dart /usr/bin/
Configure Flutter
Run flutter doctor and check for any issues. Fix the required issues as mentioned:
flutter doctor
If you don't plan to develop for web, you don't need to install chrome. Ignore that error.
If you don't plan to develop for your system, say linux, then you don't need to install clang and other packages as they mention.
You don't need android studio for flutter, you can use Codium or some other editor as well.
If they show fix android licenses issue, run:
flutter doctor --android-licenses
For Linux Development
If you're planning to develop for linux install base-devel, clang and ninja:
sudo pacman -Syy base-devel clang ninja
Emulator : Waydroid setup
Prerequisite: Kernel Module
Waydroid requires binder_linux kernel module for it to work. You can either install binder_linux-dkms from aur or install linux-zen kernel.
To install binder_linux-dkms, first install linux-headers:
sudo pacman -Syy linux-headers
Then install binder_linux-dkms from aur using your aur helper:
yay -Syy binder_linux-dkms
Alternatively, you can install it from chaotic aur if you have the repo enabled:
sudo pacman -Syy binder_linux-dkms
Once done, we can install waydroid
Install Waydroid
Install waydroid from aur using your aur helper:
yay -Syy waydroid
Alternatively, you can install it from chaotic aur if you have the repo enabled:
sudo pacman -Syy waydroid
Install Android Image
You can install either install Android image free from gapps known as vanilla or the one with gapps.
For installing vanilla image:
sudo waydroid init
For installing gapps image:
sudo waydroid init -s GAPPS
Start Waydroid
First enable waydroid container service:
sudo systemctl enable --now waydroid-container
You can launch the waydroid ui (view it like an emulator with full ui of android) from waydroid icon in your desktop environment or from the following command:
waydroid show-full-ui
Launch full UI to start the session. This will turn your waydroid on.
Install apps:
waydroid app install $path_to_apk
Enable network access through firewall
If you run something like ufw enable ports 67, 53 and allow packet forwarding, else you cannot use the internet from waydroid. If you don't run a firewall in your linux installation, ignore this.
Enable ports and packet forwarding in ufw:
sudo ufw allow 67
sudo ufw allow 53
sudo ufw default allow FORWARD
Enable USB Debugging
Goto settings inside waydroid and first unlock developer options by repeatedly clicking build number in about screen till they notify that developer mode is unlocked. Then enable USB Debugging from developer mode settings.
Connect ADB to Waydroid
List devices
adb devices
You'll find a device with address some-ip-here:port-number. Connect to that. (port number is usually 5555)
adb connect some-ip-here:port-number
Fix rotation in waydroid
By default the Waydroid is in Landscape mode. To make the window size to that of portrait mode, run:
waydroid prop set persist.waydroid.height 1280
waydroid prop set persist.waydroid.width 720
Now stop waydroid session:
waydroid session stop
Restart waydroid container service:
sudo systemctl restart waydroid-container
Now start waydroid again:
waydroid show-full-ui
Scale Display
You can scale the display from the settings app inside the waydroid. Launch full ui and then click on the settings app inside the android. Goto display settings and goto Display size settings. Now adjust the slider till you find the scaling resolution good for you.
Undo Portrait mode
To undo the above portrait mode settings, run:
waydroid prop set persist.waydroid.height ""
waydroid prop set persist.waydroid.width ""
Now stop waydroid session:
waydroid session stop
Restart waydroid container service:
sudo systemctl restart waydroid-container
Now start waydroid again:
waydroid show-full-ui