Coder Social home page Coder Social logo

android-studio-builder-1's Introduction

team project

Third-Party Licences

By building this docker image you confirm that you accept Google's Android SDK and Android NDK licenses (https://developer.android.com/studio/terms).

Prerequisites

  • Linux machine (other OS also probably fine, but some tuning might be needed)
  • At least 50 GB free disk space
  • Latest and greatest Docker (18.0 or newer)

Step-by-step guide (for Linux)

  1. Clone this repository, and navigate inside the checked out directory
  2. Setup AOSP_ROOT environment variable. If you have AOSP sources downloaded - you can use them. Otherwise just create an empty folder and make AOSP_ROOT pointing to it. We will download sources later.
export AOSP_ROOT=</path/to/parent/of/"tools"/dir, or empty dir>
  1. Run the script
sh ./rundevmode.sh
  1. it will build docker image
  2. it will start docker container and will make a 3-4 folders shared between the docker and the host (e.g. $AOSP_ROOT, ~/.cache/bazel, ~/.cache/.m2 and ~/.cache/.gradle)

image.png

Now when we have docker container up and running, all the following commands should be executed inside Docker (not inside the host):

  1. $AOSP_ROOT is now mounted to /aosp/src inside the container. If $AOSP_ROOT was pointing to an empty directory, this is good time to download the sources. Sources will be downloaded to /aosp/src inside the container, and will be availabe at $AOSP_ROOT on the host.
cd /aosp/src && sh /aosp/builder/scripts-vcs/runrepo.sh
  1. Apply patches to the sources otherwise they won't compile
cd /aosp/src && sh /aosp/builder/patches/runpatches.sh
  1. Build Android Studio dependencies with bazel
cd /aosp/src && /aosp/src/tools/base/bazel/bazel build //tools/adt/idea/android:artifacts

image.png

Now go back to the host, open $AOSP_ROOT/tools/adt/idea in IDEA and click rebuild project

  • Use Android Studio run configuration to run Android Studio from sources.

Understanding the guide

Google builds Android Studio with Bazel (Blaze). They have a huge monorepo which contains a lot of sources and binaries. Some parts of this monorepo are visible from https://android.googlesource.com/, others are private. To checkout sources special tool is needed - repo. Sources contain not only Java/Koltin code, but also native C/C++ code, and one needs Android SDK and Android NDK to build it properly.

The solution is as follows: sources are shared between the host and docker container. Sources can be loaded to IDEA on the host, but there are a few JARs which should be generated by Bazel. In order to build them we create Docker container and run Bazel there.

Sources are downloaded with a repo tool. Docker container has a copy of repo inside. repo is smart enough to ignore unreachable repositories. Usually it is safe to ignore warnings that some remote repository is not found.

Sources from AOSP are built with Bazel. Original Bazel files reference some other files from private repositories. Patches (runpatches.sh) are removing these dependencies. Additionally, patches are removing private modules (e.g. google-appindexing) from modules.xml, which do not compile anyway.

Sharing the files between the Docker and the Host is yet another challenging task. Files on the host are owned by $USERNAME. which has its own id and gid. As part of the container setup dev-local/setuplocaluser.sh is executed that creates a user inside the docker. If you have problems with permissions on files - this is the first place to check.

android-studio-builder-1's People

Contributors

andrei-kuznetsov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

android-studio-builder-1's Issues

Mac os docker run failed

Hi,when i run sh rundevmode.sh,I get some error message,such as can't find bind path.

I check rundevmode.sh , find USERNAME had not been assign. So I assign it USERNAME="xxxxx" and mkdir all source path.

But when I run sh rundevmode.sh,it can't start docker,I don't know why... can you help me?

android-studio-builder % sh rundevmode.sh

  • : /Users/song/AndroidProject/studio-master-dev
    ++ id -gn
  • GROUPNAME=staff
    ++ id -g
  • GROUPID=20
    ++ id -u
  • USERID=502
    +++ dirname rundevmode.sh
    ++ cd .
    ++ pwd
  • MYDIR=/Users/song/AndroidProject/android-studio-builder
  • USERNAME=song
  • echo 'sh /aosp/builder/dev-local/setuplocaluser.sh 502 20 song staff'
  • docker build --target builder-dev -t androidstudio-builder-dev:latest .
    [+] Building 1.2s (10/10) FINISHED
    => [internal] load build definition from Dockerfile 0.0s
    => => transferring dockerfile: 84B 0.0s
    => [internal] load .dockerignore 0.0s
    => => transferring context: 2B 0.0s
    => [internal] load metadata for docker.io/library/ubuntu:18.04 1.1s
    => [builder 1/6] FROM docker.io/library/ubuntu:18.04@sha256:538529c9d229fb55f50e674 0.0s
    => CACHED [builder 2/6] WORKDIR /aosp 0.0s
    => CACHED [builder 3/6] RUN apt-get update && apt-get install -y curl 0.0s
    => CACHED [builder 4/6] RUN update-alternatives --install /usr/bin/gcc gcc /usr 0.0s
    => CACHED [builder 5/6] RUN mkdir /aosp/bin && curl https://storage.googleapis. 0.0s
    => CACHED [builder 6/6] RUN curl https://dl.google.com/android/repository/sdk-tools 0.0s
    => exporting to image 0.0s
    => => exporting layers 0.0s
    => => writing image sha256:79284bd574dc9d1fc6dc08dff0d7cadcdfeda482e23797524317d961 0.0s
    => => naming to docker.io/library/androidstudio-builder-dev:latest 0.0s
  • docker run -it --name rundevmode --rm --mount type=bind,source=/Users/song/AndroidProject/studio-master-dev,target=/aosp/src --mount type=bind,source=/Users/song/AndroidProject/android-studio-builder,target=/aosp/builder --mount type=bind,source=/Users/song/.cache/bazel,target=/Users/song/.cache/bazel --mount type=bind,source=/Users/song/.m2,target=/Users/song/.m2 --mount type=bind,source=/Users/song/.gradle,target=/Users/song/.gradle androidstudio-builder-dev:latest
    /aosp/builder/dev-local/setuplocaluser.sh
    groupadd: group 'staff' already exists

invalid item in dependencies list

Env:
CPU: AMD 5950x;
OS: Linux liuyu-pc 5.11.0-25-generic #27~20.04.1-Ubuntu x86_64 GNU/Linux;
Docker:version 20.10.7, build f0df350

Steps:
follow the steps in README.md,build successfully,then import project to IDEA,appears errors like below :

Module intellij.android.projectSystem.gradle.sync: invalid item 'studio-sdk' in the dependencies list Module intellij.android.projectSystem.gradle.sync: invalid item 'studio-plugin-junit' in the dependencies list Module intellij.android.projectSystem.gradle.sync: invalid item 'studio-plugin-Kotlin' in the dependencies list Module intellij.android.projectSystem.gradle.sync.tests: invalid item 'studio-sdk' in the dependencies list Module intellij.android.projectSystem.gradle.sync.tests: invalid item 'studio-plugin-Kotlin' in the dependencies list Module intellij.android.projectSystem.gradle.sync.tests: invalid item 'studio-plugin-junit' in the dependencies list Module google-cloud-tools-as: invalid item 'studio-sdk' in the dependencies list Module google-cloud-tools-as: invalid item 'studio-plugin-Kotlin' in the dependencies list Module google-cloud-tools-as: invalid item 'studio-plugin-gradle' in the dependencies list Module google-cloud-tools-as: invalid item 'studio-plugin-Groovy' in the dependencies list Module google-cloud-tools-as: invalid item 'studio-plugin-git4idea' in the dependencies list Module intellij.android.build-attribution: invalid item 'studio-sdk' in the dependencies list Module intellij.android.build-attribution: invalid item 'studio-plugin-gradle' in the dependencies list Module intellij.android.build-attribution: invalid item 'studio-plugin-Kotlin' in the dependencies list Module intellij.android.build-attribution.tests: invalid item 'studio-sdk' in the dependencies list Module intellij.android.build-attribution.tests: invalid item 'studio-plugin-Kotlin' in the dependencies list Module intellij.android.build-attribution.tests: invalid item 'studio-plugin-gradle' in the dependencies list and so on.

Did you encounter the problem?
Any ideas? :)

how to release the Android studio I have edited

Hello,Sorry to bother you again.
I have followed your method and built android studio on windows.What's more,I have added corresponding features to the Android Studio project. I just want to ask you how to release the android studio, as the others need to use the features.I'm looking for methods,but no idea. If you have any idea,please leave some suggestions. Thanks a lot

Cannot build on Mac

Hey, I have step to last step
Now go back to the host, open $AOSP_ROOT/tools/idea in IDEA and click rebuild project

But I have a problem. A kotlin compiler problem( just I guessed :( ).
It seems that IntelliJ's version cant compatible with kotlin plugin.
Can you tell me your IntelliJ version and your kotlin plugin version? Or other suggest can you give me?
Thanks!
If you can give me your email address to help me solve some problem. That's great!

Can build android-studio on windows ?

Hello.Sorry to bother you,but I have to say that you just did a very amazing work!!! That's very awsome!!!
I want to know if you have any idea about how to build android studio on windows. I've been busy with this for a few weeks,but nothing worked out. It is a great luck to see your amazing work!! So I see a glimmer of hope. If you have any idea about this, hope you can give some Precious suggestions.

And I have a question, if I follow your steps,deleting some module fileurl ,then I can get right build result on windows? Because When I build on windows, always meet error about bazel ......

Thanks a lot and very sorry to bother you.

Out of sync with latest Android Studio

On the latest studio-master-dev (which I just learned is deprecated in favor of studio-main!), it looks like some patches have gotten conflicts:

/aosp/src$  sh /aosp/builder/patches/runpatches.sh
+ : /aosp/src
+ hash /aosp/bin/repo
+ REPO=/aosp/bin/repo
+ : /aosp/bin/repo
+ dirname /aosp/builder/patches/runpatches.sh
+ cd /aosp/builder/patches/..
+ pwd
+ CFG_ROOT_DIR=/aosp/builder
+ PATCHES=/aosp/builder/patches
+ SRC=/aosp/src
+ cd /aosp/src
+ mkdir -p /aosp/src/tools/vendor/google/android-ndk/includes
+ cp /aosp/builder/patches/tools.vendor.google.android-ndk.BUILD /aosp/src/tools/vendor/google/android-ndk/BUILD
+ curl https://android.googlesource.com/platform/art/+/master/openjdkjvmti/include/jvmti.h?format=TEXT
+ base64 -d
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  102k    0  102k    0     0   432k      0 --:--:-- --:--:-- --:--:--  434k
+ cd /aosp/src/tools/base
+ git apply /aosp/builder/patches/tools.base.bazel.patch
error: patch failed: bazel/kotlin.bzl:57
error: bazel/kotlin.bzl: patch does not apply
error: patch failed: bazel/src/com/android/tools/kotlin/KotlinCompiler.java:47
error: bazel/src/com/android/tools/kotlin/KotlinCompiler.java: patch does not apply
error: patch failed: bazel/toplevel.WORKSPACE:10
error: bazel/toplevel.WORKSPACE: patch does not apply
error: patch failed: build-system/integration-test/integration-tests.gradle:70
error: build-system/integration-test/integration-tests.gradle: patch does not apply

Side note: This project is wonderful. Thank you for compiling such a convenient way to solve this problem. I wish it weren't a problem to begin with, but until that becomes a priority for the Android Studio team, I'm very happy this project exists.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.