Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added dockerfile for linux and android #407

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rohansen856
Copy link
Contributor

@rohansen856 rohansen856 commented Dec 18, 2024

Description

Please include a summary of the change and which issue is fixed. List any dependencies that are required for this change.

Fixes #391

Replace issue_no with the issue number which is fixed in this PR

Screenshots

Summary

Three files in total was added in this PR

  • docker compose file
  • Dockerfile.linux
  • Dockerfile.android
    Using these files we can run flutter in containerized environment in both android and linux. For android device, We can either run it in an emulator or through a connected android device. There may be some native device problems due to the adb setup. It can be fixed using:
adb kill-server

Check again for all connected emulators:

adb devices
  • command to run in linux mode:
sudo docker-compose --profile linux up 
  • command to run in android mode:
sudo docker-compose --profile android up 
  • Added different files for android and linux as the android sdk is quite heavy and unneccesary for non-android emulators.

Checklist

  • Tests have been added or updated to cover the changes
  • Documentation has been updated to reflect the changes
  • Code follows the established coding style guidelines
  • All tests are passing

@rohansen856
Copy link
Contributor Author

@BrawlerXull @Pavel401 I have added the containers and observed them to be running locally. I think there should be an update in the contributing file to add the functionality to run the app in containerized mode. Please let me know if anymore changes would be required. thank you.

Copy link
Member

@Pavel401 Pavel401 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please share some outputs? Specifically, a screen recording demonstrating how this will benefit the contributors. I haven’t come across any open-source Flutter repositories that support Docker.

@rohansen856
Copy link
Contributor Author

Could you please share some outputs? Specifically, a screen recording demonstrating how this will benefit the contributors. I haven’t come across any open-source Flutter repositories that support Docker.

Of course @Pavel401 I will do a screenrecording and show how the docker is working to setup the entire project with just 1 command.
The main benifit is that the flutter, dart and android sdk versionsof many devices vary and due to that the app might not work in many local devices (already happened with me!), the only solution would be updating local version of them, but as open source contributors might need to maintain several applications with their own desired version, it would become very problematic to constantly keep changing local dependency versions. AlthoughFVM` solves the problem to an extent but i's still prone to many errors.
The best solution is to containerize the application using docker so that maintaining local version is not an issue any more!

About other flutter repos, they may not be that focused on open source contributors so they might not expect the developers to face the constant versioning problem i think... Nevertheless containerizing the app would definitely make it easier to get the app up and running in an instant without any versioning hassle. Thank you.

@rohansen856
Copy link
Contributor Author

A Screen Recording of the running container

Screencast.from.2024-12-19.18-33-26.webm

@Pavel401
Copy link
Member

@BrawlerXull Any thoughts?

@BrawlerXull
Copy link
Collaborator

@rohansen856 Can you please share running our project with android emulator?

@rohansen856
Copy link
Contributor Author

@rohansen856 Can you please share running our project with android emulator?

sure... but there is an urgent issue for creating permission screens before 15th. would complete that asap and attach the app running in android emulator in docker.

@BrawlerXull
Copy link
Collaborator

@rohansen856 Can you please share running our project with android emulator?

sure... but there is an urgent issue for creating permission screens before 15th. would complete that asap and attach the app running in android emulator in docker.

Works! Complete it according to your convenience :)

@rohansen856
Copy link
Contributor Author

rohansen856 commented Jan 30, 2025

@BrawlerXull here are the screenrecording of the app running on Pixel 6 API 35 emulator using docker. (had to upload the video on multiple chunks because of video file size restrictions on github)

Screencast.from.2025-01-30.14-56-02.webm
Screencast.from.2025-01-30.15-11-14.webm
Screencast.from.2025-01-30.15-13-23.webm
Screencast.from.2025-01-30.15-25-23.webm
Screencast.from.2025-01-30.15-26-53.webm

@rohansen856
Copy link
Contributor Author

rohansen856 commented Jan 30, 2025

Note: I have got another Dockerfile for the android emulator which does the same thing but is a bit more explanatory and customizable:

FROM ubuntu:20.04

ENV UID=1000
ENV GID=1000
ENV USER="developer"
ENV JAVA_VERSION="8"
ENV ANDROID_TOOLS_URL="https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip"
ENV ANDROID_VERSION="29"
ENV ANDROID_BUILD_TOOLS_VERSION="29.0.3"
ENV ANDROID_ARCHITECTURE="x86_64"
ENV ANDROID_SDK_ROOT="/home/$USER/android"
ENV FLUTTER_CHANNEL="stable"
ENV FLUTTER_VERSION="2.2.1"
ENV FLUTTER_URL="https://storage.googleapis.com/flutter_infra/releases/$FLUTTER_CHANNEL/linux/flutter_linux_$FLUTTER_VERSION-$FLUTTER_CHANNEL.tar.xz"
ENV FLUTTER_HOME="/home/$USER/flutter"
ENV FLUTTER_WEB_PORT="8090"
ENV FLUTTER_DEBUG_PORT="42000"
ENV FLUTTER_EMULATOR_NAME="flutter_emulator"
ENV PATH="$ANDROID_SDK_ROOT/cmdline-tools/tools/bin:$ANDROID_SDK_ROOT/emulator:$ANDROID_SDK_ROOT/platform-tools:$ANDROID_SDK_ROOT/platforms:$FLUTTER_HOME/bin:$PATH"

# install all dependencies
ENV DEBIAN_FRONTEND="noninteractive"
RUN apt-get update \
  && apt-get install --yes --no-install-recommends openjdk-$JAVA_VERSION-jdk curl unzip sed git bash xz-utils libglvnd0 ssh xauth x11-xserver-utils libpulse0 libxcomposite1 libgl1-mesa-glx sudo \
  && rm -rf /var/lib/{apt,dpkg,cache,log}

# create user
RUN groupadd --gid $GID $USER \
  && useradd -s /bin/bash --uid $UID --gid $GID -m $USER \
  && echo $USER ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USER \
  && chmod 0440 /etc/sudoers.d/$USER

USER $USER
WORKDIR /home/$USER

# android sdk
RUN mkdir -p $ANDROID_SDK_ROOT \
  && mkdir -p /home/$USER/.android \
  && touch /home/$USER/.android/repositories.cfg \
  && curl -o android_tools.zip $ANDROID_TOOLS_URL \
  && unzip -qq -d "$ANDROID_SDK_ROOT" android_tools.zip \
  && rm android_tools.zip \
  && mkdir -p $ANDROID_SDK_ROOT/cmdline-tools/tools \
  && mv $ANDROID_SDK_ROOT/cmdline-tools/bin $ANDROID_SDK_ROOT/cmdline-tools/tools \
  && mv $ANDROID_SDK_ROOT/cmdline-tools/lib $ANDROID_SDK_ROOT/cmdline-tools/tools \
  && yes "y" | sdkmanager "build-tools;$ANDROID_BUILD_TOOLS_VERSION" \
  && yes "y" | sdkmanager "platforms;android-$ANDROID_VERSION" \
  && yes "y" | sdkmanager "platform-tools" \
  && yes "y" | sdkmanager "emulator" \
  && yes "y" | sdkmanager "system-images;android-$ANDROID_VERSION;google_apis_playstore;$ANDROID_ARCHITECTURE"

# flutter
RUN curl -o flutter.tar.xz $FLUTTER_URL \
  && mkdir -p $FLUTTER_HOME \
  && tar xf flutter.tar.xz -C /home/$USER \
  && rm flutter.tar.xz \
  && flutter config --no-analytics \
  && flutter precache \
  && yes "y" | flutter doctor --android-licenses \
  && flutter doctor \
  && flutter emulators --create \
  && flutter update-packages

COPY entrypoint.sh /usr/local/bin/
COPY chown.sh /usr/local/bin/
COPY flutter-android-emulator.sh /usr/local/bin/flutter-android-emulator
ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]

should I update the Dockerfile.android or the previous one would suffice...?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

feat: Containerization
3 participants