Sunteți pe pagina 1din 23

Android

B. Vasu Dev
vasu@easyarm.com

Enabling the Embedded Learning in INDIA

Android Architecture

More details at: http://developer.android.com/guide/basics/what-is-android.html

Agenda
Android Source
Android Build System
Adding new code in Android Build System
Building & Executing C Code on Android Device
Debugging C/C++ using GDB
Experimenting & Understanding JAVA JNI
Compiling Android Source
Building Android RootFS

Android Source
|-- bionic ==> Not glib/uclib
|-- bootable ==> boot and startup related code
|-- build
==> build setup files
|-- cts
==> Android certification
|-- dalvik ==> DVM/JVM
|-- development =>source for NDK/SDK
|-- device ==> New devices are added her
|-- external ==> open souce lib / execuatle / helper
|-- frameworks =>service / server
|-- hardware => bluetoth/wlan/camera/gpio/sensor
|-- kernel
==> optional
|-- ndk
==> NDK
|-- out
==> out/target/product
|-- packages ==> All packaes contact/calnder
|-- prebuilt ==> tool chains are placed here
|-- sdk
=>SDK
|-- system ==>source code files for the core Android
system. That is the minimal Linux system that is started
before the Dalvik VM and any java based services are
enabled
`-- u-boot

Android Build System


GNU Make based build system
Uses some pre-set environment variables and make files.
.mk extension for Android Makefile
Build output is in out/host & /out/target
Build abstraction layers ( Product, Device, Board, Arch )
Build Variants ( eng, user, userdebug )
Make <rule>
targets )

( all, droid, clean, dataclean, showcommands, <LOCAL_MODULES>,

build/envsetup.sh script to set the environment variables

Android Build System Android.mk


LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE
:= hello-jni
LOCAL_SRC_FILES := hello-jni.c
include $(BUILD_SHARED_LIBRARY)
include $(BUILD_STATIC_LIBRARY)
include $(BUILD_EXECUTABLE)
LOCAL_STATIC_LIBRARIES := libcutils libc
LOCAL_SRC_FILES := \
src/add.c \
src/code.c

beaglebone_gb$ source build/envsetup.h


beaglebone_gb$choosecombo
Build for the simulator or the device?
1. Device
2. Simulator
Which would you like? [1] 1
Build type choices are:
1. release
2. debug
Which would you like? [1] 1
Which product would you like? [generic] beaglebone
Variant choices are:
1. user
2. userdebug
3. eng
Which would you like? [eng] 3

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.3.4
TARGET_PRODUCT=beaglebone
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=false
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=GRJ22
============================================
beaglebone_gb$ printconfig
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.3.4
TARGET_PRODUCT=beaglebone
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=false
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=GRJ22
============================================

Adding new code in Android Build System


make a directory under 'external'
e.g. ANDROID/external/myprogram
create your C/cpp files.
create Android.mk as clone of external/ping/Android.mk
Change the names ping.c and ping to match your C/cpp files and
program name
add the directory name in ANDROID/build/core/main.mk after
external/zlib as
external/myprogram
make from the root of the source tree

beaglebone_gb/external/myprogram$ . ../../build/envsetup.sh
beaglebone_gb/external/myprogram$ mm
TARGET_PRODUCT=beaglebone
Adding CUSTOM_LOCALES [mdpi hdpi] to PRODUCT_LOCALES []
make: Entering directory
`/home/alexander/projects/android/work/BeagleBone/beaglebone_gb'
target thumb C: my_program <= external/myprogram/my_program.c
target Executable: my_program
(out/target/product/beaglebone/obj/EXECUTABLES/my_program_inter
mediates/LINKED/my_program)
target Non-prelinked: my_program
(out/target/product/beaglebone/symbols/system/bin/my_program)
target Strip: my_program
(out/target/product/beaglebone/obj/EXECUTABLES/my_program_inter
mediates/my_program)
Install: out/target/product/beaglebone/system/bin/my_program
make: Leaving directory
`/home/alexander/projects/android/work/BeagleBone/beaglebone_gb'

Debugging
Android SDK includes a useful logging utility class called android.util.Log.
The Log.e() method is used to log errors.
The Log.w() method is used to log warnings.
The Log.i() method is used to log informational messages.
The Log.d() method is used to log debug messages.
The Log.v() method is used to log verbose messages.
The Log.wtf() method is used to log terrible failures that should never
happen. (WTF stands for What a Terrible Failure! of course.)
import android.util.Log;
public class MySimpleAppActivity extends Activity {
private static final String DEBUG_TAG= "MySimpleAppLogging";
Log.i(DEBUG_TAG, "Info about MySimpleAppActivity.");

radio View the buffer that contains radio/telephony related messages.


events View the buffer containing events-related messages.
main View the main log buffer (default)
The usage of the -b option is:

#define LOG_TAG "AT"


#include <utils/Log.h>
void AT_DUMP( const char* buff, int len)
{
if (len < 0)
len = strlen(buff);
LOGD("%.*s", len, buff);
}
LOGD("atchannel: read error %s", strerror(errno));
LOGE
LOGW
LOGI
LOGV
LOGD

JNI

public class MainActivity extends Activity {


NativeLib nativeLib;
String operator=null;
res = nativeLib.add(v1, v2);
res = nativeLib.mul(v1, v2);
res = nativeLib.divide(v1, v2);
package com.example.ndkdemo;
public class NativeLib
{
Static {
System.loadLibrary("ndkMathsDemo"); }
public native int add( int x, int y );
public native int mul(int x, int y);
public native int divide(int x, int y);
}

Create C Header File


project/bin/classes$ javah -jni com.example.ndkdemo.NativeLib
/project/bin/classes$ ls
com com_example_ndkdemo_NativeLib.h
cp com_example_ndkdemo_NativeLib.h jni
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_example_ndkdemo_NativeLib */
#ifndef _Included_com_example_ndkdemo_NativeLib
#define _Included_com_example_ndkdemo_NativeLib
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_example_ndkdemo_NativeLib
* Method: add
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_com_example_ndkdemo_NativeLib_add
(JNIEnv *, jobject, jint, jint);

Android for Beaglebone product


beaglebone.mk
This file will include build/target/product/generic.mk file to the build
system. Product & Company specific property variables are added in this
file
AndroidBoard.mk
Android build system will look this file by defaut. This file will take care of
copying board specific files to final rootfs ie driver modules
AndroidProducts.mk
Android build system will look this file by defaut. This file will points to the
Beagle specific make file (beaglebone.mk)
BoardConfig.mk
Product-specific compile-time definitions will defined in this file. Android
framework and more packages make files will use this variables which is
defined here

Service Manager
==============
The APIS needed to manage the services are provided by the ServiceMangaer.
Source of ServiceManager
The ServiceManager source can be found in the file
frameworks/base/core/java/android/os/ServiceManager.java

SystemServer
============
This SystemServer service is the master of all Java service. On boot time this
service starts all the Java services. In this file you can find the list of Java
services started. Presently the services are hard coded in this file. If you want
your service to be started at the boot time adding it here will start it
automatically.
Services are hard coded
Presently the services initialised by the SystemServer are hard coded.

frameworks/base/services/java/com/android/server/SystemServer.java
SystemServer Initialisation
Once the system server is started it will print the log as Entered the Android system server!
which can be view using logcat. Then it starts the ServerThread which in turn starts the
services which are listed below.
Critical services
Entropy Service
Power Manager
Activity Manager
Telephony Registry
Package Manager
Account Manager
Content Manager
System Content Providers
Battery Service
Lights Service
Vibrator Service
Alarm Manager
Init Watchdog
Sensor Service
Window Manager
Note: If any of the above system services failed to start, you will get exception "Failure
starting core service"

Additional services
Bluetooth Service
Device Policy
Status Bar
Clipboard Service
Input Method Service
NetStat Service
NetworkManagement Service
Connectivity Service
Throttle Service
Accessibility Manager
Mount Service
Notification Manager
Device Storage Monitor
Location Manager
Search Service
Demo Thread
DropBox Service
Wallpaper Service
Audio Service
Headset Observer - Listen for wired headset changes
Dock Observer - Listen for dock station changes
UI Mode Manager Service - Listen for dock station changes
Backup Service
AppWidget Service
Recognition Service

S-ar putea să vă placă și