Open nickveliki opened 1 year ago
so I encountered a few problems, found a few solutions so that I can actually get the container to build
New DOCKERFILE
#-------------------------------------------------------------------------------------------------------------
# Flutter Dev Container - Lucas Hilleshein dos Santos.
# Licensed under the MIT License.
# See https://github.com/lucashilles/flutter-dev-container/blob/master/LICENSE for license information.
#-------------------------------------------------------------------------------------------------------------
FROM ubuntu:latest
#Locale
ENV LANG C.UTF-8
# This Dockerfile adds a non-root user with sudo access. Use the "remoteUser"
# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs
# will be updated to match your local UID/GID (when using the dockerFile property).
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
#
# Install needed packages, setup user anda clean up.
RUN apt update \
&& apt install -y sudo \
&& apt install -y openjdk-11-jdk-headless --no-install-recommends \
&& apt install -y wget curl git xz-utils zip unzip --no-install-recommends
# Clean Up
RUN apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
# [Optional] Add sudo support for the non-root user
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME \
&& su $USERNAME \
&& cd $HOME
#
# Android SDK
# https://developer.android.com/studio#downloads
ENV ANDROID_SDK_TOOLS_VERSION=8512546
ENV ANDROID_PLATFORM_VERSION=33
ENV ANDROID_BUILD_TOOLS_VERSION=33.0.0
ENV ANDROID_HOME=/home/vscode/android-sdk-linux
ENV ANDROID_SDK_ROOT="$ANDROID_HOME"
ENV PATH=${PATH}:${ANDROID_HOME}/cmdline-tools/cmdline-tools/bin:${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/emulator
#
# Flutter SDK
# https://flutter.dev/docs/development/tools/sdk/releases?tab=linux
ENV FLUTTER_CHANNEL="stable"
ENV FLUTTER_VERSION="3.3.4"
# Make sure to use the needed channel and version for this.
ENV FLUTTER_HOME=/home/vscode/flutter
ENV PATH=${PATH}:${FLUTTER_HOME}/bin
#
# Android SDK
RUN curl -C - --output android-sdk-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS_VERSION}_latest.zip \
&& mkdir -p ${ANDROID_HOME}/ \
&& unzip -q android-sdk-tools.zip -d ${ANDROID_HOME}/cmdline-tools/ \
&& rm android-sdk-tools.zip \
&& yes | sdkmanager --licenses \
&& touch $HOME/.android/repositories.cfg \
&& sdkmanager platform-tools \
&& sdkmanager emulator \
&& sdkmanager "platforms;android-${ANDROID_PLATFORM_VERSION}" "build-tools;$ANDROID_BUILD_TOOLS_VERSION" \
&& sdkmanager --install "cmdline-tools;latest"
# create emulator android
RUN sdkmanager "system-images;android-${ANDROID_PLATFORM_VERSION};google_apis;x86_64"
# breaks on current avdmanager because it can't be run non-interactively, run AFTER setting up container
# RUN avdmanager create avd -n Android${ANDROID_PLATFORM_VERSION} -k "system-images;android-${ANDROID_PLATFORM_VERSION};google_apis;x86_64" -s
#
# Flutter SDK
RUN curl -C - --output flutter.tar.xz https://storage.googleapis.com/flutter_infra_release/releases/${FLUTTER_CHANNEL}/linux/flutter_linux_${FLUTTER_VERSION}-${FLUTTER_CHANNEL}.tar.xz
RUN tar -xf flutter.tar.xz -C /home/vscode/
RUN rm flutter.tar.xz
#RUN echo $PATH
RUN flutter config --android-sdk "${ANDROID_SDK_ROOT}"
RUN yes | flutter doctor --android-licenses
RUN flutter config --no-analytics
# run AFTER setting up dev container, throws an error when run by docker build
# RUN flutter update-packages
new devcontainer.json
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
// https://github.com/lucashilles/flutter-dev-container
{
"name": "Flutter",
"dockerFile": "Dockerfile",
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"dart-code.dart-code",
"dart-code.flutter"
],
// This command create an example project after the container is created.
// creates test project as root, we no like
// "postCreateCommand": "flutter create test_project",
// Use 'forwardPorts' to make a list of ports inside the container available locally.
//"forwardPorts": [],
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "vscode"
}
This solution did work for me
Improved version of @nickveliki -s docker file
#-------------------------------------------------------------------------------------------------------------
# Flutter Dev Container - Lucas Hilleshein dos Santos
# Licensed under the MIT License.
# See https://github.com/lucashilles/flutter-dev-container/blob/master/LICENSE for license information.
#-------------------------------------------------------------------------------------------------------------
FROM ubuntu:latest
#Locale
ENV LANG C.UTF-8
# This Dockerfile adds a non-root user with sudo access. Use the "remoteUser"
# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs
# will be updated to match your local UID/GID (when using the dockerFile property).
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
#
# Install needed packages, setup user anda clean up.
RUN apt update \
&& apt install -y sudo \
&& apt-cache search openjdk \
&& apt install -y openjdk-17-jdk-headless --no-install-recommends \
&& apt install -y wget curl git xz-utils zip unzip --no-install-recommends
# Clean Up
RUN apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
# [Optional] Add sudo support for the non-root user
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME \
&& su $USERNAME \
&& cd $HOME
#
# Android SDK
# https://developer.android.com/studio#command-tools - "Command line tools only" section
ENV ANDROID_SDK_TOOLS_VERSION=10406996
ENV ANDROID_PLATFORM_VERSION=33
ENV ANDROID_BUILD_TOOLS_VERSION=33.0.0
ENV ANDROID_HOME=/home/vscode/android-sdk-linux
ENV ANDROID_SDK_ROOT="$ANDROID_HOME"
ENV PATH=${PATH}:${ANDROID_HOME}/cmdline-tools/cmdline-tools/bin:${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/emulator
#
# Android SDK
RUN curl -C - --output android-sdk-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS_VERSION}_latest.zip \
&& mkdir -p ${ANDROID_HOME}/ \
&& unzip -q android-sdk-tools.zip -d ${ANDROID_HOME}/cmdline-tools/ \
&& rm android-sdk-tools.zip \
&& yes | sdkmanager --licenses \
&& touch $HOME/.android/repositories.cfg \
&& sdkmanager platform-tools \
&& sdkmanager emulator \
&& sdkmanager "platforms;android-${ANDROID_PLATFORM_VERSION}" "build-tools;$ANDROID_BUILD_TOOLS_VERSION" \
&& sdkmanager --install "cmdline-tools;latest"
# create emulator android
RUN sdkmanager "system-images;android-${ANDROID_PLATFORM_VERSION};google_apis;x86_64"
RUN echo "no" | avdmanager create avd -n Android${ANDROID_PLATFORM_VERSION} -k "system-images;android-${ANDROID_PLATFORM_VERSION};google_apis;x86_64"
#
# Flutter SDK
# https://flutter.dev/docs/development/tools/sdk/releases?tab=linux
ENV FLUTTER_CHANNEL="stable"
ENV FLUTTER_VERSION="3.13.1"
# Make sure to use the needed channel and version for this.
ENV FLUTTER_HOME=/home/vscode/flutter
ENV PATH=${PATH}:${FLUTTER_HOME}/bin
#
# Flutter SDK
RUN curl -C - --output flutter.tar.xz https://storage.googleapis.com/flutter_infra_release/releases/${FLUTTER_CHANNEL}/linux/flutter_linux_${FLUTTER_VERSION}-${FLUTTER_CHANNEL}.tar.xz
RUN tar -xf flutter.tar.xz -C /home/vscode/
RUN rm flutter.tar.xz
RUN flutter config --android-sdk "${ANDROID_SDK_ROOT}"
RUN yes | flutter doctor --android-licenses
RUN flutter config --no-analytics
RUN git config --global --add safe.directory /home/vscode/flutter
RUN flutter update-packages
@Akiyamka and @nickveliki, Thank you for the improvements. It helped me solve my build issues. Wouldn't it be better to create a PR based on your suggestions?
@camcam1773 if you would like to, you have my approval to do it with my solution. I considered this repo abandoned until I saw your and @Akiyamka's comments just now. The project which I wanted this for has also since changed to electron with react-ts