Android offers few emulators for development purposes. As a part of standard AOSP (Android Open Source Project), these emulators come in handy for development such as customization, debugging, middleware development, app development etc. But for underlying hardware access most of the other higher-level developments can be done over these emulators. There are quiet a few variants of emulators such as for general Phone/Tablet emulation or for automotive purposes – Car Emulator. This blog will focus primarily on building Android car emulator and running it in the system. We will also touch up on compiling the kernel from the source and running them as well.
Downloading AOSP source for emulation
First thing to start building car emulator is to finalize on the release version we want to build against. The list of supported variants is available in the Codenames, Tags, and Build Numbers page from the android web site. Based on the requirements, identify the version – in this case let us assume we want to build for OPM6.171019.030.B1. Note the build version it corresponds to android-8.1.0_r33.
Now we will have to download the source code for the same. Android source code is in fact a collection of git repositories. Each of the major directories in the AOSP corresponds to a separate repository. Since it is difficult to manage such a large code base individually one by one, Google has created a tool called repo that helps in this process. Install this tool with the following steps
Now that the tool is downloaded, set up your git configuration using the following commands
Assuming you are running Ubuntu 16.04, to prepare the environment, execute the following
Install the dependencies:
Identify the working directory and create it if necessary.
Switch to the directory
As mentioned earlier, we need the manifest file to being with. This initial file can be set up using the following commands.
The above command will download an XML file called “manifest.xml” that contains information about all the git repositories that constitute the AOSP.
Since the above command will download a large set of objects including previous versions, if you want to limit the download size, you can set the downloaded version depth to 1.
With everything set, being the download using the following command.
Building Car Emulator
We can now start building Android car emulator. Once again being a large project, it is better to set up a compiler cache so that the incremental builds are quite faster.
Below output confirms that the command executed successfully.
Powered by the Soong build system, the AOSP employs a variety of tools to build the source and create the images. Jack compiler used employs a server mechanism where by a single process running in the system compiles files. To configure the same, execute the below commands such that the Java based tool uses the configured amount of RAM for the JVM. In this example, it is limited to 6GB.
With every thing set up now for building the source, now configure the environment variables used by the Android build system using
The source command simply executes the given script in the same shell so that its environment variables are affected. Below output is shown
Now choose the platform you want to build. For example, we can either build the car emulator for 32-bit X86 system or 64-bit x86 system.
For building for 32-bit, use the below command.
For 64-bit use,
Typically, you will see the below output.
Initiate the build now with make command. To leverage the multiple CPU cores, present in your host machine, specify a number corresponding to it.
It will take about 1 hour to 3 hours for the build to complete depending on the host system configuration.
Running the Car Emulator
Once the build is completed, the images will be created inside the out/target/< product >/directory. The emulator can now be invoked using
Typically, you will see the emulator running as below.
Now you can connect to it over ADB and perform various operations such as installing a new App, debugging it, modifying the AOSP source and testing it etc.
Compiling the kernel
The emulator can be launched to show the kernel output and console by using the show kernel option as below.
In the login, we can check the kernel version using uname command.
We can see, this emulator runs kernel version 3.18.74+. Looking for the source, it can be found that it is available in the repository as commit c57e557. Download the same using the below commands:
Get goldfish branch c57e55706abeffafbc52d28155297650dae6e2c0
Build the same using the following commands:
The output kernel will now be available at arch/boot/x86/bzImage
This image can be used for the emulator when launching as follows:
By giving uname now, it can be seen that the build time/machine reflects
Building Android Car Emulator and running it in the system helps to accelerate various platform/application developments. It is possible to complete some part of underlying driver/HAL development using this kernel in this approach.
About Embien: Embien Technologies is a leading service provider for the Android technologies including Android porting, HAL development, HIDL developments, custom system services, deployment, App development etc. Our team extensively uses emulator for speeding up the developments even before the underlying hardware is available. Apart for developing Auto-infotainment systems, customized tablets, Home Automation consoles, rugged handhelds, Industrial HMI’s, our SMEs offers corporate training covering topics such as Android Platform development, Android for Automotive and Linux Device Drivers.