안드로이드 원격 빌딩에서mainframer를 사용해 보도록 하겠습니다.

11185 단어 Android

mainframer란?


창고의 Readme는 다음과 같습니다.
Tool that allows you to move build process from a local machine to a remote one.
이것은 구축 과정을 로컬 기계에서 원격 기계로 이동하는 도구다.
계속 이러고 있어.
Remote machine ought to be much faster than a laptop.
With mainframer you can free up your local machine for better things
— like editing source code in your IDE without lags and freezes, being able to actually use your computer when the build is happening.
리모컨은 반드시 무릎 위의 컴퓨터보다 빨라야 한다.
mainframer를 사용하면 로컬 기기를 열 수 있어 더욱 중요합니다.
예를 들어 실제 구축을 진행할 때 코드 편집은 라그나 다운이 없는 상황에서 IDE를 통해 할 수 있다.
(일역은 전혀 자신이 없다)
즉, 구축은 다른 기계에 의뢰하는 것이고 현지에서 더욱 중요한 것은 기계 자원을 사용하는 내용이라는 것을 이해한다.

mainframer가 지원하는 것


기본적으로 모든 명령줄을 지원할 수 있습니다.
현재 안드로이드 이외에 사용할 수 있는 샘플 앱이 준비돼 있다.
  • Gradle
  • Gradle Android
  • Rust
  • Clang
  • GCC
  • Maven
  • Buck
  • Go
  • 이번에는 그레이드 안드로이드의 샘플 앱을 보면서 GCE를 원격 기기로 사용해 보았다.

    원격 구축


    GCE 인스턴스 준비


    여기 기사를 참고했어요.Google ComputeEngine 인스턴스에서 Android 애플리케이션 구축
    이상의 기사를 참고하면 별다른 문제가 없을 것 같지만 비망록으로 절차를 작성할 수도 있을 것 같습니다.

    프로젝트 작성


    Google Cloud Platform 관리 화면을 열면 항목을 선택할 수 있습니다.
    캡처하는 동안 항목remote-build-android을 선택했습니다. 여기를 클릭하면 새 프로젝트를 만들거나 다른 프로젝트를 선택할 수 있는 대화 상자가 열립니다.

    나는 새 항목을 적절하게 명명하고 만들 것이다.

    인스턴스 생성하기


    현재 생성된 프로젝트에 새 GCE 인스턴스를 생성합니다.
    Conpute Engine 선택

    Create Instance 를 선택합니다.

    영역, 기계 유형, 디스크 등은 참고된 문장과 같다.

    정적 IP 설정


    인스턴스를 만들 때 화면에 정적 IP를 사용하도록 설정합니다.
    External IP 를 선택합니다.

    마음대로 이름을 짓다.

    나는 첫 번째 화면External IP에 IP address 같은 것이 나타날 것이라고 생각한다.
    이거 이따가 쓸게요.

    SSH 공개 키 등록


    실례를 만들 때 추가할 수 있지만, 나중에 추가하는 방식으로 설명할 것입니다.
    Metadata 를 선택하고 SSH Keys 를 선택한 후 아래 화면에서 Edit 키를 누르면 키를 등록할 수 있습니다.

    Add item을 누르면 다시 입력할 수 있기 때문에 수중에 만든 공개 키에 로그인합니다.

    공개 키의 제작과 등록은 이쪽 공식 문서를 참고하세요.
    Generating a new SSH key-pair
    여기까지 하면 ssh로 연결된 거 확인할 수 있을 거예요.
    $ssh -i ~/.ssh/my-ssh-key [ssh-keyge時に指定したusername]@[GCEの静的IP]
    

    안드로이드 구문을 가능하게 만들기


    방금 만든 실례는 안드로이드의 구축을 가능하게 합니다.
    프로그램은 대체로 여기에 쓰여 있다.
    Establishing a Build Environment
    ssh로 연결하고 명령을 입력하십시오.
    이 근처는 매번 번거롭기 때문에 Docker나 Ansible이 스스로 준비하는 것이 좋다고 생각합니다. 저도 Google Contener Engine 방법을 사용하고 싶습니다.
    ssh로 로그인합니다.
    # 必要になるパッケージをまとめてインストール
    $sudo apt-get install -y git-core gnupg flex bison gperf build-essential \
      zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 \
      lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache \
      libgl1-mesa-dev libxml2-utils xsltproc unzip
    
    # java8のインストール
    $ sudo apt-get update
    $ sudo apt-get install openjdk-8-jdk-headless
    
    # Android SDKのインストール
    $ wget https://dl.google.com/android/android-sdk_r24.4.1-linux.tgz
    $ tar xvf android-sdk_r24.4.1-linux.tgz
    
    # ANDROID_HOMEを設定する
    $ vim ~/.bashrc
    
    
    # If not running interactively, don't do anything 행에 추가되지 않은 경우 ANDROID홈이 없는 오류가 발생할 수 있으므로 주의가 필요하다.
    # この2行を.bashrcに追加する
    export ANDROID_HOME=~/android-sdk-linux
    PATH=$PATH:$ANDROID_HOME/tools
    
    # If not running interactively, don't do anything
    case $- in
        *i*) ;;
          *) return;;
    esac
    
    # サポートライブラリーとかをアップデート
    # 数字は `$android list sdk` で確認できます
    $ android update sdk -u -t 1,2,3,4,21,23
    
    # ライセンスファイルをコピーしておく
    # ローカルの`$ANDROID_HOME/licenses/android-sdk-license`の内容をコピーして貼り付ける感じです
    # 参考 http://qiita.com/Nkzn/items/b9a0ddd1345fb78d7d44
    $vim $ANDROID_HOME/licenses/android-sdk-license
    
    
    이렇게 하면 안드로이드의 구축 상태가 됩니다.

    local 환경 정돈


    로컬 기기의 설정은mainframer의 원격 구축을 허용하기 위해 아래 절차에 따라 실행됩니다.
    gojuno/mainframer/SETUP_LOCAL.md

    ~/.ssh/config에 방금 만든 원격 장치에 연결하는 설정 추가

    Host {REMOTE_MACHINE_ALIAS} # 適当に、僕はgcp-remote-buildにしてあります
      User {REMOTE_MACHINE_USERNAME} # ssh key作成時のusernameを記入
      HostName {REMOTE_MACHINE_IP_OR_HOSTNAME} # GCEの静的IPを記入
      Port 22
      IdentityFile ~/.ssh/{SSH_KEY_NAME}
      PreferredAuthentications publickey
      ControlMaster auto
      ControlPath /tmp/%r@%h:%p
      ControlPersist 1h
    

    원격 빌드 프로젝트 사용


    mainflamer.다음 링크에서sh의 최신 버전을 가져와 프로젝트의 노선에 설정합니다.
    https://github.com/gojuno/mainframer/releases/latest
    프로젝트 경로에 폴더.mainframer를 생성하고 네 개의 파일을 생성합니다.
    .mainframer/
    ├── config
    ├── ignore
    ├── localignore
    └── remoteignore
    
    # config
    # ~/.ssh/configに記入したHost名
    remote_machine={REMOTE_MACHINE_ALIAS}
    
    # ignore
    # .gradle folder contains machine specific loc and bin files, no need to sync it between machines.
    .gradle
    
    # Synching .git or other VCS folders is very bad idea, they are usually very heavy and not required for the build.
    .git
    
    # Synching IDE specific folders is really not needed for remote build.
    /.idea
    
    # Synching local.properties usually very bad idea because they contain machine specific properties like paths to SDKs and so on.
    /local.properties
    
    # Syncing captures from Android Studio is usually not required.
    /captures
    
    # localignore
    # Usually you don't need to sync build folder to remote machine since it will have one as result of build.
    build
    
    # remoteignore
    # Usually you don't need to sync sources back from remote to local machine.
    # Btw, this syntax supports multimodule Gradle projects.
    src
    
    설정은 이쪽 샘플대로 진행됐습니다.
    https://github.com/gojuno/mainframer/tree/development/samples/gradle-android/.mainframer
    여기까지 오면 지령으로 원격 구축을 할 수 있을 거예요.
    $bash ./mainframer.sh ./gradlew assembleDebug
    

    Android Studio에서 원격으로 구성 가능


    새 Configration을 추가하려면 다음 섹션을 클릭하고 Edit Configrations를 선택합니다.

    신규 추가Android App를 선택합니다.

    Name이 Remote-build를 알 수 있도록 Module 선택 app, 원래 쓴 것 Gradle-aware Make 을 삭제하고 다음 포획 내용을 추가합니다.


    이렇게 하면 Android Studio에서 원격 빌드를 사용하여 터미널에서 실행할 수 있습니다.

    최후


    기술적으로 ssh와 rsync를 자주 사용하지만gradle의 지령을 직접 사용할 수 있기 때문에 추천합니다.
    아직 다 되지는 않았지만 Docker로 준비하면 이 글을 참고할 수 있을 것 같아요.
    Speed-up Android builds with Mainframer (Docker container in a powerful remote machine)
    마지막 안드로이드 스튜디오의 설정에도 intellij를 위한 플러그인이 있기 때문에 저쪽 플러그인을 사용할 수도 있습니다.
    elpassion/mainframer-intellij-plugin

    mainflamer 참조 URL


    https://github.com/gojuno/mainframer/tree/development/samples/gradle-android
    https://github.com/gojuno/mainframer/blob/development/docs/SETUP_LOCAL.md
    https://github.com/gojuno/mainframer/blob/development/docs/SETUP_REMOTE.md
    https://github.com/gojuno/mainframer/blob/development/docs/CONFIGURATION.md

    좋은 웹페이지 즐겨찾기