- Welcome to the Android Emulator
- Just get me started with development!
- About the Emulator
- Recommended Reading
- Building the Emulator
- Contributing code
- Code Reviews
- Merging downstream Qemu
- QEMU для Android
- How to install Android SDK and setup AVD Emulator without Android Studio
- Understanding the Android SDK
- Installing the Android SDK
- Step 1 — Download the tools package
- Step 2— You need Java 8!
- Step 3 — Download the essential packages
- Step 4 — Set your environmental variables
- Step 5 — Download the platform specific packages you want
- Step 5 — Create a AVD device
- Step 6 — Run the Android Emulator
Welcome to the Android Emulator
This document gives you some background on the emulator and outlines how you can start hacking and contributing to the emulator!
Just get me started with development!
Make sure to install Android Studio and the associated SDKs. Do not forget to install the official emulator and create a few android virtual devices. Next follow the instructions for the platform you would like to work on:
We use the Repo tool to manage working accross multiple branches.
About the Emulator
The Android Emulator simulates Android devices on your computer so that you can test your application on a variety of devices and Android API levels without needing to have each physical device.
The emulator provides almost all of the capabilities of a real Android device. You can simulate incoming phone calls and text messages, specify the location of the device, simulate different network speeds, simulate rotation and other hardware sensors, access the Google Play Store, and much more.
Testing your app on the emulator is in some ways faster and easier than doing so on a physical device. For example, you can transfer data faster to the emulator than to a device connected over USB.
The emulator comes with predefined configurations for various Android phone, tablet, Wear OS, and Android TV devices.
Recommended Reading
The following is a list of concepts that are important. Please read these links and any other links you can find. If you find a link that you think does a better job at explaining the concept, please add it here:
QEMU is an open source competitor to VMware Workstation, VirtualBox, HyperV. It is focused on Linux server virtualization on Linux servers. While QEMU does support booting other OS’s, we don’t use that functionality since Android is Linux.
The Android Emulator is downstream from the QEMU emulator. It adds support for booting Android devices, emulates typical Android hardware (OpenGL, GPS, GSM, Sensors) and a GUI interface. The android emulator extends qemu in various ways.
For an overview of Qemu see:
The QEMU emulator leverages technologies like hardware Hypervisors KVM (Linux) and HAXM (Windows/Mac)
The QEMU emulator supports both guest images that require full virtualization and guest images that require paravirtualization technologies like virtio
The emulator passes a device tree blob to a guest kernel to describe the guest hardware
When running a non-x86 image on an x86 host, QEMU will JIT the non-x86 code into x86 code. See this lectutre for more. The MMU (page table hardware) is emulated in software, which is unfortunately slow.
You will need to build Android kernels and system images that the emulator will run. The easiest way to obtain these is to make use of the publicly released images. You can find more details here.
Building the Emulator
The emulator uses Cmake as a meta build generator, and all the necessary compilers and toolchains are included in the repository. Make sure you have read the section above as the requirements to succesfully build vary slightly from platform to platform.
In general you can run the following script:
For incremental builds you can use ninja . For example
Contributing code
The emulator uses a coding style derived from the Chromium style. We use the repo tool to submit pathces. The usual workflow is roughly as follows:
This will create a git branch called my_awesome_feature . You can now work on your patch.
Once you have written a patch you can send it out for code review. We use gerrit for code reviews.
Use the repo tool to upload or update a CL:
- “—cbr” means “upload the current branch”,
- “—re” supplies the initial reviewers list
Add “-t” switch to use the current git branch as a review topic (topic groups CLs together and only allows them to be submitted when all got +2/+verified)
The repo tool will provide you with a url where you can find your change.
Code Reviews
Make sure to check the CL against our coding style: coding style. Coding style isn’t frozen: just edit it in our repository and create a code review to propose a change.
Some good articles on code reviewing, especially when it comes to google:
- The CL Author’s Guide, which gives detailed guidance to developers whose CLs are undergoing review.
- How to Do a Code Review, which gives detailed guidance for code reviewers.
Below are some short notes relevant to the emulator.
Keep in mind that all of the code reviews are open source and visible to everyone!. In other words, be nice and and provide actionable constructive feedback.
C++ over C for all new code. Always.
After uploading a CL for review, author should “+1” it when they think it’s ready for reviewing. A CL without author’s “+1” is a “work in progress” and other reviewers may ignore it..
Prefer not to send a WIP CL to reviewers and only add them when it’s in a reviewable state. If you realized that you added reviewers too soon, just remove them — “x” button in the browser UI for each reviewer actually works.
Avoid large CLs. There are always exceptions, use your best judgement to improve code clarity and to help other maintainers in the future.
Split the changes into smaller isolated chunks and submit those as a single topic If you touch multiple components, that’s a good way to split the CL.
Changes into any QEMU files must be in their own CL — otherwise rebasing into the new version becomes 10x more painful.
“-2” is sticky, it remains there until the very same reviewer removes it. If you “-2”-ed someone, it’s always a good thing to communicate to them about the follow-up
Abandon the CLs you don’t need anymore
Tests: when reviewing the code, make sure there’s a test or a really good reason for its absence
Merging downstream Qemu
Merging changes from the qemu branch should be done on the emu-master-qemu branch. You will need to this on a linux machine as qemu development happens in a linux environment. Once you have obtained this branch you can add the remote qemu repository as follows:
Now you can start merging in changes:
Be smart, merge only a few commits at a time
Next you should try to build qemu standalone:
Now you are ready for building, testing, and merging the next set. You could have a look at this script to automate this slightly.
Источник
QEMU для Android
Я помню, когда система Windows 95 была желанной целью быть установленной у себя на компьютере. И я помню, некоторые удивительные и качественные игры под Windows 95. Конечно, компьютерные операционные системы прошли долгий путь развития и совершенство с тех пор, и мне сейчас не очень хочется играть в них на компьютере, но возможно я бы поиграл в них на телефоне.
В поисках эмуляторов для Android я наткнулся на QEMU for Android. QEMU – свободная программа, с помощью которой Вы можете эмулировать процессор x86 и устройства ввода-вывода. Портированный человеком с ником mamaich QEMU (он же портировал и эмулятор BOSCH), поддерживает экраны с разрешением более VGA и Android версии более 1.6. Для работы эмулятора требуется много оперативной памяти.
Чтобы установить QEMU на устройство под управлением довольно быстро развивающийся системы Android надо проделать всего 3 простых шага:
- Установить APK файл
- Cкопировать папку SDL и img образ в корень карты памяти
- Запустить эмулятор
Чтобы примонтировать образ к системе в эмуляторе, надо в конфиге sdl.conf написать:
/sdl -L . -m 16 -boot c -hda mount.img -usb -usbdevice tablet
Где:
16 – количество оперативной памяти, выделяемой эмулятором для ОС
mount.img – образ операционной системы
Чтобы примонтировать iso образ надо добавить аргумент cdrom:
/sdl -L . -m 16 -cdrom disc.iso -hda mount.img -boot -usb -usbdevice tablet
Если сравнивать эмуляторы BOSCH и QEMU, то оказывается, что BOSCH стабильный, но медлительный, а QEMU практически не тормозит, но имеет много багов. Есть эмуляция звуковой карты SB16, но нет поддержки MIDI синтезатора. Эмуляция математического сопроцессора неполная и поэтому некоторые не запускаются.
Управление мышью происходит с помощью сенсорного экрана и похоже на управления тач-пэдом. Эмулируются некоторые клавиши клавиатуры – например, кнопка меню – Enter, кнопки регулирования громкости – клавиши стрелок вверх и вниз соответственно.
Скорость Windows 9x на телефоне очень высока, но мешает маленький экран. У меня смартфон с разрешением VGA, поэтому играть практически невозможно, но просто, чтобы поностальгировать можно и запустить Windows 95.
На данный момент mamaich прекратил разработки данной программы и предоставил исходные коды своего труда.
Источник
How to install Android SDK and setup AVD Emulator without Android Studio
If you are trying to develop to Android, you probably will end up installing the Android Studio to get the Android SDK and the AVD Emulator working properly.
But if you are using another code editor, like Sublime Text or VSCode, installing the Android Studio will just mess up with your setup and consume your precious RAM for no good reason.
I had a hard time figuring out how to properly do this setup due the lack of documentation about it, so i hope this article helps you. 🙂
Recommended previous knowledge:
- SDK (Standard Development Kit); Read about on Wikipedia;
- AVD (Android Virtual Device); Read about on docs;
- CLI (Command Line Interface); Read about on Wikipedia;
- Android API levels; Read about on Vanderbilt University;
- How to open, navigate and execute files in your OS terminal;
- Know what are environmental variables;
Understanding the Android SDK
Basically, the Android SDK is a bunch of packages necessary to develop for Android.
These packages stays in subfolders of a folder called “sdk” (or “android-sdk” sometimes). You do not need to know how these packages really work, just what they do.
The picture below is my Android SDK folder, these are the basic packages you will need in order to get everything working properly.
Here is a brief explanation of each package:
- tools: This package is mainly used to manage the other packages and to create AVD’s;
- emulator: As the name suggest, this is the Android emulator;
- platform-tools: Some tools to communicate with Android devices when you plug then in your computer;
- patcher: This package is automatically downloaded by the SDK. I didn’t find what exactly this is for, so just leave it as it is;
The folders bellow contain sub-folders with the packages for each Android API level.
- platforms: The platform packages are required to compile your app for the specified API level.
- system-images: These are the android images used in the emulator.
- build-tools: These are necessary to build your Android apps
Installing the Android SDK
In order to install the SDK we will use the Command Line Tools. These are some quite simple CLI’s used to manage the Android SDK. You can read the documentation here for more details.
Step 1 — Download the tools package
First, you need to download the tools package. And with this package you can download the others.
- First, go to the Android Studio download page: https://developer.android.com/studio;
- Then click in “ Download Options”;
- There you will find a table named “ Command line tools only”;
- This table contain some zip files. Download the appropriate file for your system ( Windows, Mac or Linux);
- Extract this zip and you will get a folder called tools: This is the tools package i explained earlier;
Create a folder anywhere you prefer to place your SDK. I recommend you to stick with one of these commonly used places:
- Globally: C:\Android\sdk or C:\android-sdk (this is not default, but i usually set my SDK here on Windows)
- One user only: C:\Users\ \AppData\Local\Android\sdk
- Globally: /Library/Android/sdk
- One user only: /Users/ /Library/Android/sdk
And move the tools folder to this new sdk folder. Make sure you have admin access to this folder and any sub-folders inside it, or the tools package will fail to download new packages.
Note: You can also download a pre-build package for your SO (like the one available on Ubuntu repository). But i do not recommend you do to so, because they probably will not be updated and will be harder to manage, since it was automatically installed.
Step 2— You need Java 8!
The Android SDK packages require Java 8. If you do not have it, you need to download. If you are using a newer version, you have to downgrade to Java 8 or you will eventually get some errors, because it is not compatible.
If you do not have the Java 8 SDK, here is how you can install it:
On Ubuntu run these commands:
- # sudo apt-get update
- # sudo apt-get install openjdk-8-jdk
Sorry for MacOS users, i don’t know how to install it on this OS.
Step 3 — Download the essential packages
Now, download the platform-tools and the emulator packages, because they contain some CLI binary files you will need later. I decided to download these packages first in order to set all the necessary environment variables at once and make the rest of the process easier.
Open a terminal window (you need to use a terminal, not the file explorer), go to your sdk folder and navigate to the /tools/bin directory.
This folder contain the SDKManager binary: this is a CLI used to list the available packages in the Google’s repository and download, update or remove them from your SDK folder.
The bellow command will list all packages installed (the first items on the list) and all packages available to download:
To download the packages, simply copy the package names and pass it as a parameter to the SDKManager CLI using the terminal:
# ./sdkmanager platform-tools emulator
If you open your sdk folder you should see these packages folders there.
Step 4 — Set your environmental variables
You need to set the below environmental variables containing the path to our SDK, so any running program can find it in your pc:
ANDROID_SDK_ROOT = Path to your SDK folder
ANDROID_HOME = The same as ANDROID_SDK_ROOT. This variable is now deprecated, but i recommend setting it because some programs still using it to locate your sdk.
And add these folders to the PATH variable, making their binary files accessible from everywhere:
To add the environment variables on WIndows, just follow these steps:
- Open the “Control Panel”;
- Go to “ System and Security” option in the side menu;
- In the window “ System Properties” open the tab “ Advanced”;
- Click in the button “ Environment Variables” in the bottom of the page;
- In the “ Environment Variables” window you will see two tables: “User Variables” and ” System Variables”.
- If you created your sdk folder for one user only, set the variables in the “ User Variables” table;
- But, if you create your sdk folder globally, set the variables in the “ System Variables” table instead;
On Linux, you can set your environment variables in many places. So i choose the ones I found the most appropriate:
- If you created your sdk folder for one user only, set your environment variables in the file
/.bashrc;
Here is how i set these variables in my Ubuntu, using the file /etc/environment:
And sorry again, no MacOS instructions for this task.
You can find more about these environmental variables in the oficial docs here.
Now your SDK is ready! If you do not need to run the emulator there’s no need to follow the next steps.
Step 5 — Download the platform specific packages you want
You need more three packages: The platform, the system-image and the build-tools. You can download these packages for any Android version you prefer. In this article, i will download the packages for the API Level 28.
Use the “ sdkmanager — list” command to find these packages and download them using the command “ sdkmanager
Here’s an example:
Step 5 — Create a AVD device
Creating a AVD device is a simple task: run the AVDManager command (this is a binary file located in the tools/bin folder of your sdk) with the create avd option, a name for the new AVD and the image you want to use.
Here is a example:
# avdmanager create avd — name android28 — package “system-images;android-28;default;x86”
You will be asked if you want to alter some configurations. You can also modify these configurations later in the file config.ini, located in the avd folder (this folder usually is created in your user folder, under the android directory). The currently active configurations can be find in the file hardware-qemu.ini (this file just will be created after the emulator runs for the first time).
Step 6 — Run the Android Emulator
Now you just need to run the emulator command (remember that we added this package to the environmental variables?):
The emulator take some time to init for the first time. But if you done everything correctly you should see this screen:
Источник