分享在docker 里面开发Android 项目

同理,flutter reactNative 也是一样的

devcontainer.json

// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
	"name": "Fei-Dev",
	// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
	"dockerComposeFile": "../docker-dev-build/docker-compose.yml",
	"service": "devcontainer",
	"workspaceFolder": "/workspace",
	"features": {
		"ghcr.io/devcontainers/features/java:1": {},
		"ghcr.io/nordcominc/devcontainer-features/android-sdk:1": {}
	},
	"customizations": {
		"vscode": {
			"extensions": [
				"DavidAnson.vscode-markdownlint",
				"isudox.vscode-jetbrains-keybindings",
				"vscjava.vscode-gradle",
				"totalcross.android-xml-editor",
				"ms-azuretools.vscode-docker",
				"adelphes.android-dev-ext",
				"fwcd.kotlin"
			]
		}
	},
	"shutdownAction": "stopCompose",

	// Use 'forwardPorts' to make a list of ports inside the container available locally.
	// "forwardPorts": [],
	// Use 'postCreateCommand' to run commands after the container is created.
	"postCreateCommand": "adb start-server && sh gradlew build",
	// "postAttachCommand": "adb connect emulator:5555"
	// Configure tool-specific properties.
	// "customizations": {},
	// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
	//fixme 尝试使用vscode 用户可以访问volume
	"remoteUser": "root"
}

docker-compose.yml

services:
  devcontainer:
    image: mcr.microsoft.com/devcontainers/base:ubuntu
    command: /bin/sh -c "while sleep 1000; do :; done"
    ports: 
      - "8080-8090"
    volumes:
      - ..:/workspace:cached
      - gradle-cache:/root/.gradle
      - top-cache:/root/.cache

  emulator:
    image: budtmo/docker-android:emulator_11.0
    ports:
      - "6080"
    environment:
      - EMULATOR_DEVICE=Samsung Galaxy S10
      - WEB_VNC=true
    devices:
      - /dev/kvm

volumes:
  gradle-cache:
  top-cache:
50 views
Comments
登录后评论
Sign In
·

借助开源项目还可以在docker 中debug ,只是debug 的时候有点慢,不过Android debug 本身也不是很快

·

容器之间会共享网络,通过adb connect emulator:5555 连接模拟器