flutter
Contents
一、flutter 安装
https://flutter.cn/docs/get-started/install
安装源国内地址:
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
flutter docker镜像打包
1、flutter
FROM --platform=linux/amd64 debian:bullseye
ARG FLUTTER_VERSION=2.2.3
ENV LANG=C.UTF-8
ENV PUB_HOSTED_URL=https://pub.flutter-io.cn
ENV FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
ENV TZ=Asia/Shanghai
ENV DEBIAN_FRONTEND=noninteractive
RUN sed -i 's/\w*.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
RUN apt-get update && apt-get upgrade -y && apt-get install -y apt-transport-https ca-certificates gnupg-agent tzdata curl git vim unzip && \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
echo $TZ > /etc/timezone && dpkg-reconfigure --frontend noninteractive tzdata
WORKDIR /opt
RUN wget https://storage.flutter-io.cn/flutter_infra_release/releases/stable/linux/flutter_linux_${FLUTTER_VERSION}-stable.tar.xz && \
tar -xf flutter_linux_${FLUTTER_VERSION}-stable.tar.xz && \
ln -s /opt/flutter/bin/flutter /usr/bin/flutter && \
rm -rf flutter_linux_${FLUTTER_VERSION}-stable.tar.xz && \
git config --global --add safe.directory /opt/flutter && \
flutter --version
WORKDIR /root
RUN mkdir -p /root/.ssh
COPY id_rsa /root/.ssh
RUN sed -i 's/^#\s*StrictHostKeyChecking.*/StrictHostKeyChecking no/g' /etc/ssh/ssh_config
2、flutter android sdk
因为gradle的原因,一次性打包速度会很慢,容易失败,可以分段打包镜像
Dockerfile.flutter-example2-b 里使用里 Dockerfile.flutter-example2-a 构建的镜像作为基础;也可以使用 Dockerfile.flutter-example1 进行一次性打包
Dockerfile.flutter-example1
FROM --platform=linux/amd64 androidsdk/android-28:latest
ARG FLUTTER_VERSION=2.2.3
ENV LANG=C.UTF-8
ENV PUB_HOSTED_URL=https://pub.flutter-io.cn
ENV FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
ENV TZ=Asia/Shanghai
ENV DEBIAN_FRONTEND=noninteractive
# change apt source
RUN sed -e "s@http://.*archive.ubuntu.com@http://mirrors.aliyun.com@g" \
-e "s@http://.*security.ubuntu.com@http://mirrors.aliyun.com@g" \
-i.bak \
-i /etc/apt/sources.list
WORKDIR /opt
RUN wget https://storage.flutter-io.cn/flutter_infra_release/releases/stable/linux/flutter_linux_${FLUTTER_VERSION}-stable.tar.xz && \
tar -xf flutter_linux_${FLUTTER_VERSION}-stable.tar.xz && \
ln -s /opt/flutter/bin/flutter /usr/bin/flutter && \
rm -rf flutter_linux_${FLUTTER_VERSION}-stable.tar.xz && \
git config --global --add safe.directory /opt/flutter && \
flutter --version
COPY ./xxxx_pad /build
WORKDIR /build
RUN flutter pub get
RUN flutter build apk --no-tree-shake-icons -t lib/main_xxxxxxxx.dart --flavor xxxxxxxxx --verbose
RUN rm -rf /build
WORKDIR /root
分段打包
# Dockerfile.flutter-example2-a
FROM --platform=linux/amd64 runmymind/docker-android-sdk:ubuntu-standalone
ARG FLUTTER_VERSION=2.2.3
ENV LANG=C.UTF-8
ENV PUB_HOSTED_URL=https://pub.flutter-io.cn
ENV FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
ENV TZ=Asia/Shanghai
ENV DEBIAN_FRONTEND=noninteractive
# change apt source
RUN sed -e "s@http://.*archive.ubuntu.com@http://mirrors.aliyun.com@g" \
-e "s@http://.*security.ubuntu.com@http://mirrors.aliyun.com@g" \
-i.bak \
-i /etc/apt/sources.list
WORKDIR /opt
RUN wget https://storage.flutter-io.cn/flutter_infra_release/releases/stable/linux/flutter_linux_${FLUTTER_VERSION}-stable.tar.xz && \
tar -xf flutter_linux_${FLUTTER_VERSION}-stable.tar.xz && \
ln -s /opt/flutter/bin/flutter /usr/bin/flutter && \
rm -rf flutter_linux_${FLUTTER_VERSION}-stable.tar.xz && \
git config --global --add safe.directory /opt/flutter && \
flutter --version
# Dockerfile.flutter-example2-b
FROM flutter-android-sdk:flutter-example2-a
COPY ./xxxxxx_pad /build
WORKDIR /build
RUN flutter pub get
RUN flutter build apk --no-tree-shake-icons -t lib/main_xxxxxxxx.dart --flavor xxxxxxxx --verbose
RUN rm -rf /build
WORKDIR /root