I try to build an APK of my Flutter application with Docker.
At the last step I have this error:
<code>> [17/17] RUN flutter build apk --release:
1.420
1.496 Running Gradle task 'assembleRelease'...
12.76 Exception in thread "main" java.net.UnknownHostException: objects.githubusercontent.com
12.76 at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:572)
12.76 at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
12.76 at java.base/java.net.Socket.connect(Socket.java:633)
12.76 at java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:304)
12.76 at java.base/sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:174)
12.76 at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:183)
12.76 at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:533)
12.76 at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:638)
12.76 at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:266)
12.76 at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:380)
12.76 at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:193)
12.76 at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1241)
12.76 at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1127)
12.76 at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:179)
12.76 at java.base/sun.net.www.protocol.http.HttpURLConnection.followRedirect0(HttpURLConnection.java:2943)
12.76 at java.base/sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2852)
12.76 at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1948)
12.76 at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1610)
12.76 at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:224)
12.76 at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
12.76 at org.gradle.wrapper.Download.download(Download.java:44)
12.76 at org.gradle.wrapper.Install$1.call(Install.java:61)
12.76 at org.gradle.wrapper.Install$1.call(Install.java:48)
12.76 at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
12.76 at org.gradle.wrapper.Install.createDist(Install.java:48)
12.77 at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
12.77 at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
12.77 Running Gradle task 'assembleRelease'... 11.3s
12.83 Gradle task assembleRelease failed with exit code 1`
</code>
<code>> [17/17] RUN flutter build apk --release:
1.420
1.496 Running Gradle task 'assembleRelease'...
12.76 Exception in thread "main" java.net.UnknownHostException: objects.githubusercontent.com
12.76 at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:572)
12.76 at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
12.76 at java.base/java.net.Socket.connect(Socket.java:633)
12.76 at java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:304)
12.76 at java.base/sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:174)
12.76 at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:183)
12.76 at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:533)
12.76 at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:638)
12.76 at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:266)
12.76 at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:380)
12.76 at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:193)
12.76 at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1241)
12.76 at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1127)
12.76 at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:179)
12.76 at java.base/sun.net.www.protocol.http.HttpURLConnection.followRedirect0(HttpURLConnection.java:2943)
12.76 at java.base/sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2852)
12.76 at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1948)
12.76 at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1610)
12.76 at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:224)
12.76 at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
12.76 at org.gradle.wrapper.Download.download(Download.java:44)
12.76 at org.gradle.wrapper.Install$1.call(Install.java:61)
12.76 at org.gradle.wrapper.Install$1.call(Install.java:48)
12.76 at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
12.76 at org.gradle.wrapper.Install.createDist(Install.java:48)
12.77 at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
12.77 at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
12.77 Running Gradle task 'assembleRelease'... 11.3s
12.83 Gradle task assembleRelease failed with exit code 1`
</code>
> [17/17] RUN flutter build apk --release:
1.420
1.496 Running Gradle task 'assembleRelease'...
12.76 Exception in thread "main" java.net.UnknownHostException: objects.githubusercontent.com
12.76 at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:572)
12.76 at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
12.76 at java.base/java.net.Socket.connect(Socket.java:633)
12.76 at java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:304)
12.76 at java.base/sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:174)
12.76 at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:183)
12.76 at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:533)
12.76 at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:638)
12.76 at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:266)
12.76 at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:380)
12.76 at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:193)
12.76 at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1241)
12.76 at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1127)
12.76 at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:179)
12.76 at java.base/sun.net.www.protocol.http.HttpURLConnection.followRedirect0(HttpURLConnection.java:2943)
12.76 at java.base/sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2852)
12.76 at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1948)
12.76 at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1610)
12.76 at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:224)
12.76 at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
12.76 at org.gradle.wrapper.Download.download(Download.java:44)
12.76 at org.gradle.wrapper.Install$1.call(Install.java:61)
12.76 at org.gradle.wrapper.Install$1.call(Install.java:48)
12.76 at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
12.76 at org.gradle.wrapper.Install.createDist(Install.java:48)
12.77 at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
12.77 at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
12.77 Running Gradle task 'assembleRelease'... 11.3s
12.83 Gradle task assembleRelease failed with exit code 1`
Here is my Dockerfile:
<code># Use a base image with necessary tools for building Flutter apps
FROM ubuntu:22.04
# Install required dependencies for Flutter, Android, and Linux development
RUN apt-get update && apt-get install -y
git
wget
unzip
curl
cmake
clang
ninja-build
pkg-config
libgtk-3-dev
liblzma-dev
openjdk-17-jdk
build-essential
libgl1-mesa-dev
&& rm -rf /var/lib/apt/lists/*
# Install Android SDK and command-line tools
RUN mkdir -p /opt/android-sdk-linux/cmdline-tools/latest &&
cd /opt/android-sdk-linux/cmdline-tools/latest &&
wget https://dl.google.com/android/repository/commandlinetools-linux-8512546_latest.zip &&
unzip commandlinetools-linux-8512546_latest.zip &&
mv cmdline-tools/* . &&
rm -rf cmdline-tools commandlinetools-linux-8512546_latest.zip
# Set environment variables for Android SDK and Flutter
ENV ANDROID_HOME=/opt/android-sdk-linux
ENV PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH
# Ensure sdkmanager is executable
RUN chmod +x /opt/android-sdk-linux/cmdline-tools/latest/bin/sdkmanager
RUN sdkmanager --version
# Accept licenses and install SDK components using sdkmanager
RUN yes | sdkmanager --licenses &&
sdkmanager "platform-tools" "platforms;android-33" "build-tools;33.0.0"
# Create the non-root user before cloning Flutter
RUN useradd -m -s /bin/bash flutteruser
# Create /opt/flutter directory and change ownership to the non-root user
RUN mkdir -p /opt/flutter && chown -R flutteruser:flutteruser /opt/flutter /opt/android-sdk-linux
# Switch to the non-root user and clone Flutter into /opt/flutter
USER flutteruser
RUN git clone https://github.com/flutter/flutter.git /opt/flutter
# Set Flutter in the PATH for non-root user
ENV PATH="/opt/flutter/bin:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH"
# Set working directory
WORKDIR /app
# Set the Flutter channel to stable and upgrade
RUN flutter channel stable && flutter upgrade
# Accept Android SDK licenses
RUN yes | flutter doctor --android-licenses
# Switch back to root to copy project files and change their ownership
USER root
# Copy the Flutter project files into the container
COPY . .
# Change ownership of the project files to flutteruser
RUN chown -R flutteruser:flutteruser /app
# Switch back to the non-root user to run the rest of the commands
USER flutteruser
# Install dependencies
RUN flutter pub get
# Check the status of the Flutter installation
RUN flutter doctor -v
# Build the APK in release mode
RUN flutter build apk --release
# The APK will be located in /app/build/app/outputs/flutter-apk/
</code>
<code># Use a base image with necessary tools for building Flutter apps
FROM ubuntu:22.04
# Install required dependencies for Flutter, Android, and Linux development
RUN apt-get update && apt-get install -y
git
wget
unzip
curl
cmake
clang
ninja-build
pkg-config
libgtk-3-dev
liblzma-dev
openjdk-17-jdk
build-essential
libgl1-mesa-dev
&& rm -rf /var/lib/apt/lists/*
# Install Android SDK and command-line tools
RUN mkdir -p /opt/android-sdk-linux/cmdline-tools/latest &&
cd /opt/android-sdk-linux/cmdline-tools/latest &&
wget https://dl.google.com/android/repository/commandlinetools-linux-8512546_latest.zip &&
unzip commandlinetools-linux-8512546_latest.zip &&
mv cmdline-tools/* . &&
rm -rf cmdline-tools commandlinetools-linux-8512546_latest.zip
# Set environment variables for Android SDK and Flutter
ENV ANDROID_HOME=/opt/android-sdk-linux
ENV PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH
# Ensure sdkmanager is executable
RUN chmod +x /opt/android-sdk-linux/cmdline-tools/latest/bin/sdkmanager
RUN sdkmanager --version
# Accept licenses and install SDK components using sdkmanager
RUN yes | sdkmanager --licenses &&
sdkmanager "platform-tools" "platforms;android-33" "build-tools;33.0.0"
# Create the non-root user before cloning Flutter
RUN useradd -m -s /bin/bash flutteruser
# Create /opt/flutter directory and change ownership to the non-root user
RUN mkdir -p /opt/flutter && chown -R flutteruser:flutteruser /opt/flutter /opt/android-sdk-linux
# Switch to the non-root user and clone Flutter into /opt/flutter
USER flutteruser
RUN git clone https://github.com/flutter/flutter.git /opt/flutter
# Set Flutter in the PATH for non-root user
ENV PATH="/opt/flutter/bin:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH"
# Set working directory
WORKDIR /app
# Set the Flutter channel to stable and upgrade
RUN flutter channel stable && flutter upgrade
# Accept Android SDK licenses
RUN yes | flutter doctor --android-licenses
# Switch back to root to copy project files and change their ownership
USER root
# Copy the Flutter project files into the container
COPY . .
# Change ownership of the project files to flutteruser
RUN chown -R flutteruser:flutteruser /app
# Switch back to the non-root user to run the rest of the commands
USER flutteruser
# Install dependencies
RUN flutter pub get
# Check the status of the Flutter installation
RUN flutter doctor -v
# Build the APK in release mode
RUN flutter build apk --release
# The APK will be located in /app/build/app/outputs/flutter-apk/
</code>
# Use a base image with necessary tools for building Flutter apps
FROM ubuntu:22.04
# Install required dependencies for Flutter, Android, and Linux development
RUN apt-get update && apt-get install -y
git
wget
unzip
curl
cmake
clang
ninja-build
pkg-config
libgtk-3-dev
liblzma-dev
openjdk-17-jdk
build-essential
libgl1-mesa-dev
&& rm -rf /var/lib/apt/lists/*
# Install Android SDK and command-line tools
RUN mkdir -p /opt/android-sdk-linux/cmdline-tools/latest &&
cd /opt/android-sdk-linux/cmdline-tools/latest &&
wget https://dl.google.com/android/repository/commandlinetools-linux-8512546_latest.zip &&
unzip commandlinetools-linux-8512546_latest.zip &&
mv cmdline-tools/* . &&
rm -rf cmdline-tools commandlinetools-linux-8512546_latest.zip
# Set environment variables for Android SDK and Flutter
ENV ANDROID_HOME=/opt/android-sdk-linux
ENV PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH
# Ensure sdkmanager is executable
RUN chmod +x /opt/android-sdk-linux/cmdline-tools/latest/bin/sdkmanager
RUN sdkmanager --version
# Accept licenses and install SDK components using sdkmanager
RUN yes | sdkmanager --licenses &&
sdkmanager "platform-tools" "platforms;android-33" "build-tools;33.0.0"
# Create the non-root user before cloning Flutter
RUN useradd -m -s /bin/bash flutteruser
# Create /opt/flutter directory and change ownership to the non-root user
RUN mkdir -p /opt/flutter && chown -R flutteruser:flutteruser /opt/flutter /opt/android-sdk-linux
# Switch to the non-root user and clone Flutter into /opt/flutter
USER flutteruser
RUN git clone https://github.com/flutter/flutter.git /opt/flutter
# Set Flutter in the PATH for non-root user
ENV PATH="/opt/flutter/bin:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH"
# Set working directory
WORKDIR /app
# Set the Flutter channel to stable and upgrade
RUN flutter channel stable && flutter upgrade
# Accept Android SDK licenses
RUN yes | flutter doctor --android-licenses
# Switch back to root to copy project files and change their ownership
USER root
# Copy the Flutter project files into the container
COPY . .
# Change ownership of the project files to flutteruser
RUN chown -R flutteruser:flutteruser /app
# Switch back to the non-root user to run the rest of the commands
USER flutteruser
# Install dependencies
RUN flutter pub get
# Check the status of the Flutter installation
RUN flutter doctor -v
# Build the APK in release mode
RUN flutter build apk --release
# The APK will be located in /app/build/app/outputs/flutter-apk/
I run my Dockerfile with the command:
docker build -t my-flutter-app .
I try also with --network=host
but I have the same error.
I think it might be a Network error but I have no idea how to solve it…
Thank you by advance for your help.
New contributor
Bastian8ify is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.