优化的Android和Flutter开发Docker镜像
docker-android-build-box是一个集成了Android SDK和Flutter SDK的优化Docker镜像。它包含多个Android SDK平台版本、构建工具、NDK和bundletool等最新Android开发工具。镜像还整合了Java、Python、Node.js和Ruby等常用开发环境。支持Bitbucket Pipelines和Github Actions,适用于CI/CD流程,简化Android和Flutter项目的构建过程。
An optimized Docker image that includes the Android SDK and Flutter SDK.
The latest image will always have the latest software installed, including the last 8 Android SDKs for platforms and associated build tools. The Dockerhub description, accessible by clicking the Docker badge above, has an always up-to-date listing of the software installed on the latest image. Please also see the matrixes file for details on the various software installed on the tagged release and the latest image.
The last tagged release includes the following components:
The docker image is automatically built publicly on Github Action based on the Dockerfile
in this repo, there is no hidden stuff in it.
To pull the latest docker image:
docker pull mingc/android-build-box:latest
Hint: You can use a tag to a specific stable version,
rather than latest
of docker image, to avoid breaking your build.
e.g. mingc/android-build-box:1.25.0
.
Take a look at the Tags List to see all the available tags, the Changelog to see the changes between tags, and the Compatibility Matrices to see matrices of the various software available, that is tag 1.2.0
has SDKs x, y, and z... etc.
Please see the caches section for how to use caching.
You can use this docker image to build your Android project with a single docker command:
cd <android project directory> # change working directory to your project root directory. docker run --rm -v `pwd`:/project mingc/android-build-box bash -c 'cd /project; ./gradlew build'
To build .aab
bundle release, use ./gradlew bundleRelease
:
cd <android project directory> # change working directory to your project root directory. docker run --rm -v `pwd`:/project mingc/android-build-box bash -c 'cd /project; ./gradlew bundleRelease'
Run docker image with interactive bash shell:
docker run -v `pwd`:/project -it mingc/android-build-box bash -l
Please be aware that caching will not reduce the total disk space needed, but will increase it. For example, with the Android SDK this will potentially double the amound of space. First there is the space needed for the image itself, and then the space needed for the cache. For example for 1.25.0
, the image needs 16.2GB of space and then if one where to cache the SDK, without any changes, then there would be an additional 6GB of space needed; 16.2GB (raw image) + SDK Cache (6GB by default).
To allow for the global java setting via jEnv, the file /root/.jenv/version
, to be cached the simplest way is to cache the complete jEnv folder, /root/.jenv/
.
First create the directory on the host where jEnv will be cached. For this example it will be in ~/.dockercache/jenv/
:
# mkdir ~/.dockercache/jenv
Second create a named volume, named jenv-cache
. A named volume is necessary to allow the container's contents of jEnv to remain. The simplest manner is as follows:
# docker volume create --driver local --opt type=none --opt device=~/.dockercache/jenv/ --opt o=bind jenv-cache
And finally when you create / run the container, be sure to include the named volume by adding the following to the command:
-v jenv-cache:"/root/.jenv/"
e.g.
# docker run --rm -v jenv-cache:"/root/.jenv/" mingc/android-build-box bash -l `echo "Hello World"`
Add the following arguments to the docker command to cache the home gradle folder:
-v "$HOME/.dockercache/gradle":"/root/.gradle"
e.g.
docker run --rm -v `pwd`:/project -v "$HOME/.dockercache/gradle":"/root/.gradle" mingc/android-build-box bash -c 'cd /project; ./gradlew build'
The final step is to turn caching on by adding:
org.gradle.caching=true
to your gradle.properties
. Either the project's gradle.properties
or the global gradle.properties
in $HOME/.dockercache/gradle/gradle.properties
.
The benefit of caching the SDK is it allows for SDK platforms / build-tools to be updated / removed in the image. For example, in 1.25.0
one could drop SDKs 27, 28, and 29; as well as adding build-tools 34. As of 1.25.0
/opt/android-sdk/
will need about 6G of disk space.
As with the jEnv cache a named volume will be needed.
First create the directory on the host where the SDKs will be cached. For this example it will be in ~/.dockercache/android-sdk/
:
# mkdir ~/.dockercache/android-sdk
Second create a named volume, named android-sdk-cache
. A named volume is necessary to allow the container's contents to remain. The simplest manner is as follows:
# docker volume create --driver local --opt type=none --opt device=~/.dockercache/android-sdk/ --opt o=bind android-sdk-cache android-sdk-cache
And finally when you create / run the container, be sure to include the named volume by adding the following to the command:
-v android-sdk-cache:"/opt/android-sdk/"
e.g.
# docker run --rm -v android-sdk-cache:"/opt/android-sdk/" mingc/android-build-box bash -l
Now within the container one may interact with the sdkmanager to install build tools, platforms, etc as needed. Some brief commands... to list what is installed:
# sdkmanager --list_installed
To uninstall a platform:
# sdkmanager --uninstall 'platforms;android-26'
To install a platform:
# sdkmanager --install 'platforms;android-26'
Both the --install
and --uninstall
flags allow for a list to be passed, that is:
# sdkmanager --uninstall 'platforms;android-26' 'platforms;android-27'
Full documentation is available here.
Setting the following jvmargs
for gradle are suggested:
-Xmx8192m
-XX:MaxMetaspaceSize=1024m
-XX:+UseContainerSupport
-XX:MaxRAMPercentage=97.5
The total memory available to the container should be greater than the Xmx value + the MaxMetaspaceSize. For example, if 10gb is allocated to the container, and using the already listed values, then we have 10gb = 8gb (Xmx) + 1gb (MaxMetaspaceSize) + 1gb (overhead / buffer / other). If the container has 4gb of memory available than the following would be reasonable settings: 4gb = 3072m (Xmx) + 756m (MaxMetaspaceSize) + 256mb (overhead / etc).
In total the gradle.properties
would be:
org.gradle.jvmargs=-Xmx8192m -XX:MaxMetaspaceSize=1024m -XX:+UseContainerSupport -XX:MaxRAMPercentage=97.5
or
org.gradle.jvmargs=-Xmx3072m -XX:MaxMetaspaceSize=756m -XX:+UseContainerSupport -XX:MaxRAMPercentage=97.5
If you have an Android project in a Bitbucket repository and want to use the pipeline feature to build it,
you can simply specify this docker image.
Here is an example of bitbucket-pipelines.yml
:
image: mingc/android-build-box:latest pipelines: default: - step: caches: - gradle - gradle-wrapper - android-emulator script: - . ~/.bash_profile - jenv global 11 # switch java version - bash ./gradlew assemble definitions: caches: gradle-wrapper: ~/.gradle/wrapper android-emulator: $ANDROID_HOME/system-images/android-21
The caches are used to store downloaded dependencies from previous builds, to speed up the next builds.
Here is an example .github/workflows/main.yml
to build a Flutter project with this docker image:
name: CI on: [push] jobs: build: runs-on: ubuntu-20.04 container: mingc/android-build-box:latest steps: - uses: actions/checkout@v3 - uses: actions/cache@v3 with: path: /root/.gradle/caches key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} restore-keys: | ${{ runner.os }}-gradle- - name: Build run: | echo "Work dir: $(pwd)" echo "User: $(whoami)" flutter --version flutter analyze flutter build apk - name: Archive apk uses: actions/upload-artifact@v3 with: name: apk path: build/app/outputs/apk - name: Test run: flutter test - name: Clean build to avoid action/cache error run: rm -fr build
Note: For improved security reference the action directly by commit hash and not tag. Please see our own action for an examples.
Using guidelines from...
...You can write a script to create and launch an ARM emulator, which can be used for running integration tests or instrumentation tests or unit tests:
#!/bin/bash # Arm emulators can be quite slow. For this reason it is convenient # to increase the adb timeout to avoid errors. export ADB_INSTALL_TIMEOUT=30 # Download an ARM system image to create an ARM emulator. sdkmanager "system-images;android-22;default;armeabi-v7a" # Create an ARM AVD emulator, with a 100 MB SD card storage space. Echo "no" # because it will ask if you want to use a custom hardware profile, and you don't. # https://medium.com/@AndreSand/android-emulator-on-docker-container-f20c49b129ef echo "no" | avdmanager create avd \ -n Android_5.1_API_22 \ -k "system-images;android-22;default;armeabi-v7a" \ -c 100M \ --force # Launch the emulator in the background $ANDROID_HOME/emulator/emulator -avd Android_5.1_API_22 -no-skin -no-audio -no-window -no-boot-anim -gpu off & # Note: You will have to add a suitable time delay, to wait for the emulator to launch.
Note that x86_64 emulators are not currently supported. See Issue #18 for details.
As of 1.23.0
, jenv
is used to switch java
versions. Versions prior to 1.23.0
used update-alternatives
; brief documentation is available here.
Please also see the installed java versions matrix for the installed java versions and jEnv Cache on how to cache the global java version.
To allow jenv
work properly, please run following command before any jenv
command:
. ~/.bash_profile
The following documentation is for jenv
. Please note that if the container is removed, that is run with the --rm
flag, global changes will not persist unless jEnv is cached.
List all the available java
versions:
# jenv versions system 11 11.0 11.0.17 17 * 17.0 (set by /root/.jenv/version) 17.0.5 1.8 1.8.0.352 openjdk64-11.0.17 openjdk64-17.0.5 openjdk64-1.8.0.352
Switch global java
version to Java 8:
root@f7e7773edb7f:/project# jenv global 1.8 root@f7e7773edb7f:/project# java -version openjdk version "1.8.0_352" OpenJDK Runtime Environment (build 1.8.0_352-8u352-ga-1~20.04-b08) OpenJDK 64-Bit Server VM (build 25.352-b08, mixed mode)
Switch global java
version to Java 11:
root@f7e7773edb7f:/project# jenv global 11 root@f7e7773edb7f:/project# java -version openjdk version "11.0.17" 2022-10-18 OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu220.04) OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu220.04, mixed mode, sharing)
Switch local, that is current folder, java
version to Java 1.8:
root@f7e7773edb7f:/project# jenv local 1.8 root@f7e7773edb7f:/project# java -version openjdk version "1.8.0_352" OpenJDK Runtime Environment (build 1.8.0_352-8u352-ga-1~20.04-b08) OpenJDK 64-Bit Server VM (build 25.352-b08, mixed mode) root@f7e7773edb7f:/project# cd .. root@f7e7773edb7f:/# java -version openjdk version "17.0.5" 2022-10-18 OpenJDK Runtime Environment (build 17.0.5+8-Ubuntu-2ubuntu120.04) OpenJDK
AI小说写作助手,一站式润色、改写、扩写
蛙蛙写作—国内先进的AI写作平台,涵盖小说、学术、社交媒体等多场景。提供续写、改写、润色等功能,助力创作者高效优化写作流程。界面简洁,功能全面,适合各类写作者提升内容品质和工作效率。
字节跳动发布的AI编程神器IDE
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。
全能AI智能助手,随时解答生活与工作的多样问题
问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。
实时语音翻译/同声传译工具
Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。
一键生成PPT和Word,让学习生活更轻松
讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。
深度推理能力全新升级,全面对标OpenAI o1
科大讯飞的星火大模型,支持语言理解、知 识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。
一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型
Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。
AI助力,做PPT更简单!
咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。
选题、配图、成文,一站式创作,让内容运营更高效
讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。
专业的AI公文写作平台,公文写作神器
AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。
最新AI工具、AI资讯
独家AI资源、AI项目落地
微信扫一扫关注公众号