Android SDK development environment Docker image
<img src="https://github.com/thyrlian/AndroidSDK/blob/master/images/logo.png?raw=true" width="200"><a href="https://youtu.be/YwBAqMDYFCU"><img src="https://pbs.twimg.com/media/DODnbwmXkAAbXuM.jpg" alt="Conference Talk" width="600"></a>
It contains the complete Android SDK enviroment, is able to perform all regular Android jobs.
Solves the problem of "It works on my machine, but not on XXX machine".
Some tool (e.g. Infer), which has complex dependencies might be in conflict with your local environment. Installing the tool within a Docker container is the easiest and perfect solution.
Works out of the box as an Android CI build enviroment.
Provide only the barebone SDK (the latest official minimal package) gives you the maximum flexibility in tailoring your own SDK tools for your project. You can maintain an external persistent SDK directory, and mount it to any container. In this way, you don't have to waste time on downloading over and over again, meanwhile, without having any unnecessary package. Additionally, instead of one dedicated Docker image per Android API level (which will end up with a ton of images), you just have to deal with one image. Last but not least, according to Android's terms and conditions, one may not redistribute the SDK or any part of the SDK.
Gradle and Kotlin compiler come together with this Docker image merely for the sake of convenience / trial.
It is recommended to always execute a build with the Wrapper to ensure a reliable, controlled and standardized execution of the build. Using the Wrapper looks almost exactly like running the build with a Gradle installation. In case the Gradle distribution is not available on the machine, the Wrapper will download it and store in the local file system. Any subsequent build invocation is going to reuse the existing local distribution as long as the distribution URL in the Gradle properties doesn’t change.
Using the Gradle Wrapper lets you build with a precise Gradle version, in order to eliminate any Gradle version problem.
<your_project>/gradle/wrapper/gradle-wrapper.properties
specifies the Gradle version~/.gradle/wrapper/dists/
kotlin-compiler-embeddable-x.y.z.jar
will be resolved and downloaded when executing a Gradle task, it's defined in <your_project>/build.gradle
as classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Previously, running Android SDK update within the Dockerfile or inside a container would fail with AUFS
storage driver, it was due to hardlink move operations (during updating Android SDK) are not supported by AUFS storage driver, but changing it to other storage driver would work. Fortunately, it's not the case any more. With the latest version of Docker Engine, it works like a charm, you can do whatever you prefer. If you're not interested in the technical cause, simply skip this section (jump to the next section).
What happens if the update fails?
ls $ANDROID_HOME/cmdline-tools/tools/ #=> empty, nothing is there # tools such as: android, sdkmanager, emulator, lint and etc. are gone android #=> bash: android: command not found sdkmanager #=> bash: /opt/android-sdk/cmdline-tools/tools/bin/sdkmanager: No such file or directory
To prevent this problem from happening, and you don't wanna bother modifying storage driver. The only solution is to mount an external SDK volume from host to container. Then you are free to try any of below approaches.
Update SDK in the usual way but directly inside container.
Update SDK from host directory (Remember: the host machine must be the same target architecture as the container - x86_64 Linux
).
If you by accident update SDK on a host machine which has a mismatch target architecture than the container, some binaries won't be executable in container any longer.
gradle <some_task> #=> Error: java.util.concurrent.ExecutionException: java.lang.RuntimeException: AAPT process not ready to receive commands $ANDROID_HOME/build-tools/x.x.x/aapt #=> aapt: cannot execute binary file: Exec format error adb #=> adb: cannot execute binary file: Exec format error
Note:
AUFS storage driver was deprecated in Docker Community Edition 18.06.0-ce-mac70 2018-07-25. And AUFS support was removed in Docker Community Edition 2.0.0.0-mac78 2018-11-19. For more details, please check Docker for Mac Stable release notes.
More information about storage driver:
Check Docker's current storage driver option
docker info | grep 'Storage Driver'
Check which filesystems are supported by the running host kernel
cat /proc/filesystems
Some storage drivers only work with specific backing filesystems. Check supported backing filesystems for further details.
In order to change the storage driver, you need to edit the daemon configuration file, or go to Docker Desktop -> Preferences... -> Daemon -> Advanced.
{ "storage-driver": "" }
# build the image # set the working directory to the project's root directory first docker build -t android-sdk android-sdk # or you can also pass specific tool version as you wish (optional, while there is default version) docker build --build-arg JDK_VERSION=<jdk_version> --build-arg GRADLE_VERSION=<gradle_version> --build-arg KOTLIN_VERSION=<kotlin_version> --build-arg ANDROID_SDK_VERSION=<android_sdk_version> -t android-sdk android-sdk # or pull the image instead of building on your own docker pull thyrlian/android-sdk # below commands assume that you've pulled the image # copy the pre-downloaded SDK to the mounted 'sdk' directory docker run -it --rm -v $(pwd)/sdk:/sdk thyrlian/android-sdk bash -c 'cp -a $ANDROID_HOME/. /sdk' # go to the 'sdk' directory on the host, update the SDK # ONLY IF the host machine is the same target architecture as the container # JDK required on the host sdk/cmdline-tools/tools/bin/sdkmanager --update # or install specific packages sdk/cmdline-tools/tools/bin/sdkmanager "build-tools;x.y.z" "platforms;android-<api_level>" ... # mount the updated SDK to container again # if the host SDK directory is mounted to more than one container # to avoid multiple containers writing to the SDK directory at the same time # you should mount the SDK volume in read-only mode docker run -it -v $(pwd)/sdk:/opt/android-sdk:ro thyrlian/android-sdk /bin/bash # you can mount without read-only option, only if you need to update SDK inside container docker run -it -v $(pwd)/sdk:/opt/android-sdk thyrlian/android-sdk /bin/bash # to keep and reuse Gradle cache docker run -it -v $(pwd)/sdk:/opt/android-sdk -v $(pwd)/gradle_caches:/root/.gradle/caches thyrlian/android-sdk /bin/bash # to stop and remove container # when the image was pulled from a registry docker stop $(docker ps -aqf "ancestor=thyrlian/android-sdk") &> /dev/null && docker rm $(docker ps -aqf "ancestor=thyrlian/android-sdk") &> /dev/null # when the image was built locally docker stop $(docker ps -aqf "ancestor=android-sdk") &> /dev/null && docker rm $(docker ps -aqf "ancestor=android-sdk") &> /dev/null # more flexible way - doesn't matter where the image comes from docker stop $(docker ps -a | grep 'android-sdk' | awk '{ print $1 }') &> /dev/null && docker rm $(docker ps -a | grep 'android-sdk' | awk '{ print $1 }') &> /dev/null
A helper script is provided at /opt/license_accepter.sh
for accepting the SDK and its various licenses. This is helpful in non-interactive environments such as CI builds.
It is also possible if you wanna connect to container via SSH. There are three different approaches.
Build an image on your own, with a built-in authorized_keys
# Put your `id_rsa.pub` under `android-sdk/accredited_keys` directory (as many as you want) # Build an image, then an `authorized_keys` file will be composed automatically, based on the keys from `android-sdk/accredited_keys` directory docker build -t android-sdk android-sdk # Run a container docker run -d -p 2222:22 -v $(pwd)/sdk:/opt/android-sdk:ro android-sdk
Mount authorized_keys
file from the host to a container
# Make sure your local authorized_keys file has the correct permission set chmod 600 $(pwd)/authorized_keys sudo chown root:root authorized_keys docker run -d -p 2222:22 -v $(pwd)/authorized_keys:/root/.ssh/authorized_keys thyrlian/android-sdk
Copy a local authorized_keys
file to a container
# Create a local `authorized_keys` file, which contains the content from your `id_rsa.pub` # Make sure your local authorized_keys file has the correct permission set chmod 600 $(pwd)/authorized_keys # Run a container docker run -d -p 2222:22 -v $(pwd)/sdk:/opt/android-sdk:ro thyrlian/android-sdk # Copy the just created local authorized_keys file to the running container docker cp $(pwd)/authorized_keys `docker ps -aqf "ancestor=thyrlian/android-sdk"`:/root/.ssh/authorized_keys # Set the proper owner and group for authorized_keys file docker exec -it `docker ps -aqf "ancestor=thyrlian/android-sdk"` bash -c 'chown root:root /root/.ssh/authorized_keys'
That's it! Now it's up and running, you can ssh to it
ssh root@<container_ip_address> -p 2222
And, in case you need, you can still attach to the running container (not via ssh) by
<img src="https://github.com/thyrlian/AndroidSDK/blob/master/images/SSH.png?raw=true">docker exec -it <container_id> /bin/bash
Remote access to the container's desktop might be helpful if you plan to run emulator inside the container.
# pull the image with VNC support docker pull thyrlian/android-sdk-vnc # spin up a container with SSH # won't work when spin up with interactive session, since the vncserver won't get launched docker run -d -p 5901:5901 -p 2222:22 -v $(pwd)/sdk:/opt/android-sdk thyrlian/android-sdk-vnc
When the container is up and running, use your favorite VNC client to connect to it:
<container_ip_address>:5901
Password (with control): android
Password (view only): docker
# setup and launch emulator inside the container # create a new Android Virtual Device echo "no" | avdmanager create avd -n test -k "system-images;android-25;google_apis;armeabi-v7a" # launch emulator emulator -avd test -no-audio -no-boot-anim -accel on -gpu swiftshader_indirect &
For more details, please refer to Emulator section.
<img src="https://github.com/thyrlian/AndroidSDK/blob/master/images/vnc.png?raw=true">You can host the Android SDK in one host-independent place, and share it across different containers. One solution is using NFS (Network File System).
To make the container consume the NFS, you can try either way below:
Mount the NFS onto your host machine, then run container with volume option (-v
).
Use a Docker volume plugin, for instance Convoy plugin.
And here are instructions for configuring a NFS server (on Ubuntu):
sudo apt-get update sudo apt-get install -y nfs-kernel-server sudo mkdir -p /var/nfs/android-sdk # put the Android SDK under /var/nfs/android-sdk # if you haven't got any, run below commands sudo apt-get install -y wget zip cd /var/nfs/android-sdk sudo wget -q $(wget -q -O- 'https://developer.android.com/sdk' | grep -o "\"https://.*android.*tools.*linux.*\"" | sed "s/\"//g") sudo unzip *tools*linux*.zip sudo rm *tools*linux*.zip sudo mkdir licenses echo 8933bad161af4178b1185d1a37fbf41ea5269c55 | sudo tee licenses/android-sdk-license > /dev/null echo 84831b9409646a918e30573bab4c9c91346d8abd | sudo tee licenses/android-sdk-preview-license > /dev/null echo d975f751698a77b662f1254ddbeed3901e976f5a | sudo tee licenses/intel-android-extra-license > /dev/null # configure and launch NFS service sudo chown nobody:nogroup /var/nfs echo "/var/nfs *(rw,sync,no_subtree_check,no_root_squash)" | sudo tee --append /etc/exports > /dev/null sudo exportfs -a sudo service nfs-kernel-server start
There is still room for optimization: recent distribution of Gradle is around 100MB, imagine different containers / build jobs have to perform downloading over and over again, and it has high influence upon your network bandwidth. Setting up a local Gradle distributions mirror server would significantly boost your download speed.
Fortunately, you can easily build such a mirror server docker image on your own.
docker build -t
字节跳动发布的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 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。
OpenAI Agents SDK,助力开发者便捷使用 OpenAI 相关功能。
openai-agents-python 是 OpenAI 推出的一款强大 Python SDK,它为开发者提供了与 OpenAI 模型交互的高效工具,支持工具调用、结果处理、追踪等功能,涵盖多种应用场景,如研究助手、财务研究等,能显著提升开发效率,让开发者更轻松地利用 OpenAI 的技术优势。
最新AI工具、AI资讯
独家AI资源、AI项目落地
微信扫一扫关注公众号