Downloading and building AOSP

I decided to share my instructions on how to build AOSP (Android Open Source Project). This manual will be useful for those who want to see something inside Android and possibly do system development. In any case, this knowledge is useful for understanding Android itself, just for this I decided to build AOSP.



I build the project on elementary 5.1 OS Ubuntu 18.04 LTS (bionic), I tried to build it on MacOS, but failed. For sources and assembly, you need 200 GB of hard disk space (better than SSD, on normal performance it sags a lot). I also spent a lot of time to download and assemble about 20 hours, partly to blame for the "weak" configuration of my computer. I have only 8 GB of RAM installed, but increased the size of the swap to 16 GB.



Loading AOSP



Install required packages for download and build:



sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig


Create a folder and download the repo utility to download the source code



mkdir aosp #     
cd aosp

curl https://storage.googleapis.com/git-repo-downloads/repo > repo
chmod a+x repo


AOSP sources consist of separate projects with their own git repositories, repo allows you to simplify the entire download of all projects and put them in the necessary folders.



Initializing the repo



./repo init -b android-10.0.0_r45 --depth 1 -u https://android.googlesource.com/platform/manifest


Parameters:



  • -u - url of git repository with manifest
  • -b - branch (most recent at the moment)
  • β€”depth β€” ( , , )


Android 10. develop master, .



AOSP



./repo sync -c  -j $(nproc) --no-tags --no-clone-bundle


:



  • -c β€” ( β€” android-10.0.0_r45)
  • -j β€” ,
  • β€”no-tags β€”
  • β€”no-clone-bundle β€” clone.bundle ( , , bundle),


β€”no-clone-bundle , , 404

, repo , : https://source.android.com/setup/develop/repo





:



source build/envsetup.sh




lunch aosp_x86_64-eng


x86_64 β€” , Generic x86_64 , Nexus , https://source.android.com/setup/build/building#choose-a-target



eng β€” ( engineering), .



java Heap size, , StackOverflow :



export _JAVA_OPTIONS="-Xmx4g"


.bashrc

, :



USE_CCACHE=1 CCACHE_DIR=ccache make -j $(nproc)


CCACHE, , . "" - 16 .



, :



emulator -show-kernel


-show-kernel β€”



Enter,



,

Emulator



IDE



IDE, IDEA. :



mmm development/tools/idegen


AOSP ,



development/tools/idegen/idegen.sh


IDEA "". . IDEA , Android



development/tools/idegen/intellij-gen.sh frameworks/base




cat .repo/project.list


base.iml ( frameworks/base) IDEA. Java, java , AOSP- .



Setting up Java in a project





monitor



 ~/Android/Sdk/tools/lib/monitor-x86_64/monitor


jre

sudo apt install openjdk-8-jre-headless

, . monitor- /8700, , IDEA.

system_process. .



monitor AOSP

monitor from Android



In the project, add a new Remote configuration, only specify port 8700. It is to this port that we will connect



Add Remote configuration to IDEA



Run Debug (Run β†’ Debug)



To make sure that everything is connected, put a breakpoint in frameworks / base / services / core / java / com / android / server / wm / ActivityTaskManagerService.java file to the method:



// line 1040
int startActivityAsUser(IApplicationThread caller, String callingPackage,
            Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode,
            int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId,
            boolean validateIncomingUser) {
//...
}


and run any application on the emulator (eg Settings).



Everything is now ready to experiment.




All Articles