28
Android internals Egor Elizarov SPbSU 2012

Android internals 03 - Build system, emulator (rev_1.1)

Embed Size (px)

DESCRIPTION

Course: Android Internals Lecture 3: Build system, emulator

Citation preview

Page 1: Android internals 03 - Build system, emulator (rev_1.1)

Android internalsEgor ElizarovSPbSU 2012

Page 2: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 20122

Legal info

Android internals by Egor Elizarov is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

You are free to – copy, distribute, display, and perform the work

– make derivative works Under the following conditions

– Attribution. You must give the original author credit

– Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one

All pictures and trademarks are the property of their respective owners. Use of these trademarks and pictures is subject to owners permissions.

Corrections, suggestions, contributions and translations are welcome!

Page 3: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 20123

Lecture 3

Android build system,

Emulator

yegor.yelizarov(at)gmail.com

http://vk.com/android_internalsRev: 1.1Last update: 05/30/2012

Page 4: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 20124

Previous time

AOSP

High level architecture

Android OS bring up

CTS & CDD

repo / git / gerrit

Code layout

Page 5: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 20125

Android build system

Based on GNU Make

Build system code is in “build” directory (./build/core/main.mk - start point)

Android.mk files

All output and temporary files are in “out” directory

Page 6: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 20126

Makefile structure

Structure:

Target: depenencies List of commands

Usage:

make target

Page 7: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 20127

Interesting files

Android.mk — build scenario for module

buildspec.mk — variable defenitions for build system

envsetup.sh — setup environment, add some helper functions

Page 8: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 20128

Sample Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_SRC_FILES := list_of_sources

LOCAL_C_INCLUDES := list_of_directories_with_header_files

LOCAL_SHARED_LIBRARIES := list_of_shared_libraries

LOCAL_STATIC_LABRARIES := list_of_static_libraries

LOCAL_MODULE_TAGS := debug

LOCAL_MODULE := module_name

include $(BUILD_EXECUTABLE)

Page 9: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 20129

More variables

LOCAL_MODULE_PATH := install_path

LOCAL_CFLAGS := flags_for_compiler

LOCAL_LDFLAGS := flags_for_linker

LOCAL_OVERRIDES_PACKAGES := packages_to_be_dropped

Etc.

Page 10: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 201210

Target hierarchyCPU type

Bare schematics

Fixed peripherals

Fixed applications

Page 11: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 201211

buildspec.mk

TARGER_PRODUCT = product_name

TARGET_BUILD_TYPE = debug

SHOW_COMMANDS = true

USE_CCACHE = 1

BUILD_TINY_ANDROID = true (board bring up/ low level debugging)

Page 12: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 201212

Some make targets

make droid (default target)

make update-api (update current API)

make sdk (build SDK)

make help (prints more targets)

Page 13: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 201213

Build process

Page 14: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 201214

Building AOSP

cd AOSP

. build/envsetup.sh

lunch

Select generic-eng version

make -j4

Page 15: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 201215

Add new program

Page 16: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 201216

Board specific files

BoardConfig.mk (Target configuration)

Board_name.mk (board related defenitions, list of packages)

Device.mk (list of files to be copied, list of packages, etc.)

Page 17: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 201217

Android emulator

Based on Qemu VM

Goldfish – codename for emulator

Code in development/tools/emulator & external/qemu

Provided as part of SDK

Page 18: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 201218

Emulator features

Runs full Android stack down to the kernel level

ARM v5 CPU and correcponding MMU

LCD with different resolutions

GSM modem

Simulates application interrupts, data channel lost, etc.

Page 19: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 201219

Qemu

Single loop for each core

Worker threads for long term tasks

Tiny Code Generator (TCG)

Kernel Virtual Machine (KVM)

Page 20: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 201220

Emulator window

Page 21: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 201221

Tools

android — control AVD, update SDK, manage android projects

emulator — launches emulator

adb — remote debug console

mksdcard — create SD card image

Page 22: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 201222

Android Debug Bridge

adb kill-server

adb devices

adb logcat

adb shell

adb push what where

adb pull what where

Page 23: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 201223

ADB internals

USB or TCP/IP

Page 24: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 201224

Launch emulator

$ out/host/linux-x86/bin/emulator &

$ adb kill-server

$ adb shell

Page 25: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 201225

Target filesystem layout

/system — main system directory

/data — main data directory

/cache — Dalvik cache

/sdcard — SD card mount point

/etc; /sys; /proc; /dev; /sbin; /root; /mnt — derived from linux

Page 26: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 201226

Next time

“Androdized” kernel

Bionic standard C library

Logging system

Source: http://androidcommunity.com

Page 27: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 201227

Useful links

http://vk.com/android_internals

http://mrbook.org/tutorials/make/

http://elinux.org/Android_Build_System

K. Yaghmour. Embedded Android. Early Release, O'Reilly, October 2011

http://developer.android.com/guide/developing/tools/emulator.html

http://developer.android.com/guide/developing/devices/emulator.html

http://blog.vmsplice.net/2011/03/qemu-internals-overall-architecture-and.html

Page 28: Android internals 03 - Build system, emulator (rev_1.1)

Egor Elizarov SPbSU 201228

Thanks to

Sergey Matyukevich for review and advices (www.linkedin.com/pub/sergey-matyukevich/31/889/769)

Nikolay F. Fominykh for review and advices

Nikita Shulga for advices and notes (http://www.linkedin.com/pub/nikita-shulga/8/582/287)