Build Flutter app in Dockerfile: Gradle Network issue

I try to build an APK of my Flutter application with Docker.

At the last step I have this error:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật