Skip to content

Commit

Permalink
[chore]:{update README.}
Browse files Browse the repository at this point in the history
  • Loading branch information
hide committed Oct 9, 2021
1 parent d4328bd commit b52debe
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 7 deletions.
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# AndroidRemoteBuildWithDocker

[简体中文](https://github.com/BruceWind/AndroidRemoteBuildWithDocker/blob/main/README_zh.md)

If you build large Android project on MacBook or other laptops, you must think your computer performance is not enough. Your laptop battery is not enough as well. And you must spend a lot time on waiting it.
So you may want a powerful and portable workstation. It is impossible but you can build on remote desktop.
The trouble on me as well but I fixed it. I used to establish a remote-builder on my powerful desktop. I control the remote-builder by not only terminal but also Android studio.
A problem is that remote-builder configuring with Android will spend lots time. In building it on a cloud service or new desktop, tremendous steps of configuration make me tired. So I made this repo integrate with a couple of technologies: Docker and [Mainframer](https://github.com/buildfoundation/mainframer).
A problem is that remote-builder configuring with Android will spend lots time. In building it on a cloud service or new desktop, tremendous steps of configuration make me tired. So I made this repo integrate with a couple of technologies: virtualization technolgy and a remote-builder tool.

The Mainframer works for remote building. Its official explain:
[Mainframer](https://github.com/buildfoundation/mainframer), the remote-builder tool is can do two things: syncing files and executing build commands. Its official explain:
> A tool that executes a command on a remote machine while syncing files back and forth. The process is known as remote execution (in general) and remote build (in particular cases).
> It works via pushing files to the remote machine, executing the command there and pulling results to the local machine.
And I have to tell you that it work not only temrinal but also Android studio.

Before I said that remote-builder configuring with Android will spend lots time but we have virtualization technology, such as `Docker` and `Kubernetes`, which I've used in everywhere is high-performance and easy to use and backup.
***In this repo, I make a docker image that contains Android environment and [Mainframer](https://github.com/buildfoundation/mainframer)***.
You can run it on your desktop in case you have a powerful/high-performance desktop. It is not required that the desktop and your laptop **under one LAN**. In case the desktop you can connect from anywhere, it can be set the docker image. Furthermore, you can put the docker image on a cloud service, such as, google or amazon cloud server, for your remote and powerful building. Cloud services are elastic in performance and price. Besides, you may think cloud server is high-latency. I have to explain that latency won't effect your building experience because mainframer does not to communitcate your laptop many times in a building process. Even copying files only in before and after buiding build. And the full-file-copy task only once.
***In this repo, I make a docker image that contains Android develop environment and [Mainframer](https://github.com/buildfoundation/mainframer)***.
You can run it on a powerful/high-performance desktop which can be a server. It is not required that the desktop/server and your laptop **under one LAN**. In case the desktop/server you can connect from anywhere, it can be set the docker image. Furthermore, you can put the docker image on a cloud service, such as, google or amazon cloud server, for your remote and powerful building. Cloud services are elastic in performance and price. Besides, you may think cloud server is high-latency. I have to explain that latency won't affect your build experience because the host does not communicate with your laptop multiple times during the build process, except during the first build. Copying files only in before and after buiding build. And the full-file-copying task only once.

To sum up, I explained that the repo works for remote-building and it solve troubles about laptop's performance and battery. So after you establish a remote-builder, you can bring you laptop to coffee shop, grass and sunshine without electric charging.

To sum up, I explained that the repo works for remote-building. It is able to solve laptop performance and save more power from battery. So after you establish a remote-builder, you can bring you laptop to coffee shop, grass and sunshine without electric charging.
Below I explain how to set up it.

## Server configuration
<details><summary>click to expand</summary>
Expand Down Expand Up @@ -46,11 +50,11 @@ Beside the project specific setup we need 2 more things, an ssh-key that is used
ControlPath /tmp/%r@%h:%p
ControlPersist 1h" >> ~/.ssh/config
```
**REPLACE IP ADDRESS**
**DONT FORGET TO REPLACE IP ADDRESS**

To SSH to the docker container: `ssh remote_builder`

For android you can now just copy the mainframer folder and rename it `.mainframer` and you should run ` bash ./mainframer.sh ./gradlew assembleDebug`.
For android you can now copy the folder `.mainframer` and file `./mainframer.sh` into your project folder. Then you can run `bash ./mainframer.sh ./gradlew assembleDebug`.

**And now enjoy faster builds**

Expand Down Expand Up @@ -87,6 +91,8 @@ For android you can now just copy the mainframer folder and rename it `.mainfram

**How to install other sdk?**

> In most circumstances, you don't need to do it. SDK downloading will automatically execute。
Modify Dockerfile to rebuild. Or follow these steps:

1. start your docker.
Expand Down
116 changes: 116 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# AndroidRemoteBuildWithDocker

当您在笔记本上编译一个大型的Android project时,可能觉得性能和电池都不够。而且,你还需要付出很多时间等待编译。
所以你一定很想要一个既高性能又便携的工作机器。那是不可能的。
我有过同样的困扰,不过我解决了。我过去常常建立一个远程编译的服务在我的台式机上。即可以用命令行控制远程编译服务,也可以使用Android Studio。
但是,有个问题是每次配置一个远程编译服务需要花很多时间。一堆步骤摆在我面前。这使我心累。所以,我做了这个repo,它同时集成了 两种技术:虚拟化技术 和 远程编译工具.


[Mainframer](https://github.com/buildfoundation/mainframer)正式我说的远程编译工具。它用于同步文件和执行编译指令. 它的官方说法:
> A tool that executes a command on a remote machine while syncing files back and forth. The process is known as remote execution (in general) and remote build (in particular cases).
> It works via pushing files to the remote machine, executing the command there and pulling results to the local machine.
我需要重复: 它不但可以用命令行控制,还可以用Android studio。

在开头,我说配置远程编译的 Android环境需要**花很多时间**,但是现在我们有虚拟化技术, 比如 `Docker` and `Kubernetes`, 这项技术我经常使用,它使用简单且易于备份。

***在这个repo里, 我创建了一个docker镜像。它同时包含Android开发环境,和[Mainframer](https://github.com/buildfoundation/mainframer)***.
如果你有高性能台式机/其他,它就是作为服务器。你可以运行这个repo在你的服务器。你的这台服务器,不要求一定与你的开发机器在 **同一局域网下*****关于这点,我需要补充的是:在中国,你可能没有外网IP,就没办法在广域网下面连接到你的这台服务器,你可以尝试内网穿透技术。***


另外,你可以把这个docker image运行在云服务上。比如 google, amazon。 为了您的远程的且高性能的编译. Cloud services在性能和价格上面往往是弹性的。另外,你可能觉得cloud server高延迟.我需要阐明 : **延迟不会影响您的编译体验**因为 mainframer不会与您的笔记本沟通得那么的频繁。仅仅第一次编译,会传输大量的文件。除第一次之外的编译,不需要同步那么多的文件。

如上所述,我介绍了该repo的远程编译解决的一些问题。它可以解决笔记本性能不够,而台式机写代码又不够便携的问题,还有电池问题。
所以,当你建立好这个远程编译服务,你可以去咖啡馆,草地上,阳光下用笔记本写代码,且不需要充电。

接下来介绍如何使用。

## Server configuration
<details><summary>click to expand</summary>
第一步是编译docker镜像。在您的terminal中, run `docker build -t mainframer-docker .`

最后一步是启动镜像为一个容器: run `docker run --restart always -d -p 23:22 mainframer-docker`.

现在,如果没有errors, run `docker container ls | grep mainframer-docker` 去观察容器是否启动。我相信一切都很正常。

</details>

## Client configuration
<details><summary>click to expand</summary>

客户端这边的步骤,我们需要做两件事,一个SSH key和一个ssh配置文件用于你的笔记本与服务器沟通。


```bash
ssh-keygen -t rsa -f ~/.ssh/remote-builder -q -N ""
#brew install ssh-copy-id
ssh-copy-id -i ~/.ssh/remote-builder -p 23 root@127.0.0.1

echo -e "Host remote_builder
User root
HostName 127.0.0.1
Port 23
IdentityFile ~/.ssh/remote-builder
PreferredAuthentications publickey
ControlMaster auto
ControlPath /tmp/%r@%h:%p
ControlPersist 1h" >> ~/.ssh/config
```
**REPLACE IP ADDRESS**

用ssh连接服务器: `ssh remote_builder`

为了Android,你拷贝我已经建立了的`.mainframer` 目录和一个文件`./mainframer.sh`到您的项目下。然后,你可以运行` bash ./mainframer.sh ./gradlew assembleDebug`去尝试启动命令行编译.

**And now enjoy faster builds**

### DEFAULT USER ROOT:ROOT IS USED IN THIS SETUP.



### 使用Android Studio远程编译

1. 用Android Studio打开 your project.

3. 点击 **Run → Edit Configuration → +**.

4. 选择 your **Android App**.

5. 使用一个新的名字, e.g. remote-build.

6.**Module**, 选择submodule name, 可能是 `app`

7.**Before Launch**, 点击 **-** 删除 `Gradle-aware Make`

8.**Before Launch**, 点击 **+**, 添加 **Run External Tool**, 输入新的名字,比如: `remote assembleDebug`.

9.**Program**, 输入 `bash`.

10.**Parameters** 输入 `mainframer.sh ./gradlew :app:assembleDebug -Pandroid.enableBuildCache=true`

11. 最后一步, 在 **Working directory** , 输入 `$ProjectFileDir$`.


</details>

## 补充

**How to install other sdk?**

> 大多数情况下这是不需要关心的事情。sdk都是会自动下载的,androidsdk都已经很智能了。
修改 Dockerfile 去重编docker镜像.或者使用如下步骤:

1. 启动 你的 docker.
2. 运行 `ssh remote_builder` 进入该 docker container. 这步可以用docker命令代替.
3. 此时你已经进入bash在你的docker容器中, run:

`/sdk/tools/bin/sdkmanager--install "ndk;21.0.6113669" --channel=3`.

**Mainframer also can build other kind of project**
You can fork this project to edit `Dockerfile` to make it work for your project.



**其他Mainframer的功能:**
[mainframer/v2.1.0 doc](https://github.com/buildfoundation/mainframer/tree/v2.1.0/samples/gradle-android)
简体

0 comments on commit b52debe

Please sign in to comment.