SlideShare a Scribd company logo
1 of 79
Download to read offline
How to Make Android Native Application
Noritsuna Imamura
noritsuna@siprop.org

©SIProp Project, 2006-2008

1
Agenda
How to Make NativeActivity Application
NativeActivityGlue

How to Draw Something
How to Use Library(OpenCV)

How to Debug NativeActivity Application
Debug
Profiling

©SIProp Project, 2006-2008

2
How to Make Native Application
with Eclipse

©SIProp Project, 2006-2008

3
Native Application
NDK wo/ADT
Standard Android
Application for C/C++
Only C/C++ on Limited
Library Layer

Call Stack
APK File(Your Application)
(C/C++)

Advantage
Only C/C++
DirectCall C/C++ API

Dis-Advantage
Use a few Android Tools
A few Docs from Google
Developer Site & Blogs

Call as C/C++ APIs

Library Layer
(C/C++)
Call as SysCall(C/ASM
Kernel/Driver Layer
(C/ASM)Project, 2006-2008
©SIProp

4
Make Android Project

©SIProp Project, 2006-2008

5
Setup App Name & Target API

©SIProp Project, 2006-2008

6
Enable JNI

©SIProp Project, 2006-2008

7
Enable JNI

©SIProp Project, 2006-2008

8
SampleNativeActivity.cpp

1. #include <jni.h>

©SIProp Project, 2006-2008

9
Android.mk

1. LOCAL_PATH := $(call my-dir)
2. include $(CLEAR_VARS)
3. LOCAL_MODULE := SampleNativeActivity
4. LOCAL_SRC_FILES :=
SampleNativeActivity.cpp
5. include $(BUILD_SHARED_LIBRARY)

©SIProp Project, 2006-2008

10
LifeCycle Diagram
Activity is Event Driven Arch
Main Event
onCreate()
Start Activity
Initialize Objects

onStart()
Finish Initialized

onPause()
Other Activity Start

onResume()
Back from Other Activity

onStop()
Don’t back long time
©SIProp Project, 2006-2008

11
LifeCycle in NativeActivity
[ndk dir]/platforms/android-19/archarm/usr/include/android
native-activity.h
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.

typedef struct ANativeActivityCallbacks {
void (*onStart)(ANativeActivity* activity);

void (*onResume)(ANativeActivity* activity);
void* (*onSaveInstanceState)(ANativeActivity*
activity, size_t* outSize);
void (*onPause)(ANativeActivity* activity);
void (*onStop)(ANativeActivity* activity);

void (*onDestroy)(ANativeActivity* activity);

©SIProp Project, 2006-2008

12
NativeActivity CallBacks
NativeActivity

Effect

onStart

= Activity.onStart()

onResume

= Activity.onResume()

onSaveInstanceState

= Activity.onSaveInstanceState()

onPause

= Activity.onPause()

onStop

= Activity.onStop()

onDestroy

= Activity.onDestroy()

onWindowsFocusChanged

Focus of Window was Changed

onNativeWindowCreated

Native Windows was Created

onNativeWindowResized

Native Window was Re-sized

onNativeWindowRedrawNeeded

Native Window was Required Re-Draw

onNativeWindowDestroyed

Native Window was Destroyed

onInputQueueCreated

InputQueue was Created

onInputQueueDestroyed

InputQueue was Destroyed

onContentRectChanged

Drawable Area was Changed (Ex.Keyboard)

onConfiguratinChanged

System Configuration was Changed

onLowMemory

System Memory was Low

©SIProp Project, 2006-2008

13
Problem Point
You MUST write it as Non-Block Function.
In other word, you MUST use “Thread”.
Thread Programing is sooooo hard…
Why? Go to Next Page!

©SIProp Project, 2006-2008

14
NativeActivityGlue CallBacks
NativeActivity

NativeActivityGlue

onStart

APP_CMD_START

onResume

APP_CMD_RESUME

onSaveInstanceState

APP_CMD_SAVE_STATE

onPause

APP_CMD_PAUSE

onStop

APP_CMD_STOP

onDestroy

APP_CMD_DESTROY

onWindowsFocusChanged

APP_CMD_GAINED_FOCUS
APP_CMD_LOST_FOCUS

onNativeWindowCreated

APP_CMD_INIT_WINDOW

onNativeWindowResized

APP_CMD_WINDOW_RESIZED

onNativeWindowRedrawNeeded

APP_CMD_WINDOW_REDRAW_NEEDED

onNativeWindowDestroyed

APP_CMD_TERM_WINDOW

onInputQueueCreated
onInputQueueDestroyed

APP_CMD_INPUT_CHANGED

onContentRectChanged

APP_CMD_CONTENT_RECT_CHANGED

onConfiguratinChanged

APP_CMD_CONFIG_CHANGED

onLowMemory

APP_CMD_LOW_MEMORY

©SIProp Project, 2006-2008

15
NativeActivityGlue
[NDK dir]/sources/android/native_app_glue
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.

void android_app_pre_exec_cmd(struct android_app* android_app,
int8_t cmd) {
switch (cmd) {
case APP_CMD_INPUT_CHANGED:
LOGV("APP_CMD_INPUT_CHANGEDn");
pthread_mutex_lock(&android_app->mutex);
if (android_app->inputQueue != NULL) {
AInputQueue_detachLooper(android_app->inputQueue);
}
android_app->inputQueue = android_app>pendingInputQueue;
if (android_app->inputQueue != NULL) {
LOGV("Attaching input queue to looper");
AInputQueue_attachLooper(android_app->inputQueue,
android_app->looper, LOOPER_ID_INPUT, NULL,
&android_app->inputPollSource);
}
pthread_cond_broadcast(&android_app->cond);
pthread_mutex_unlock(&android_app->mutex);
break;
©SIProp Project, 2006-2008

16
Sample of NativeActivityGlue
Don’t Need to Use “thread” Funcs.

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.

static void engine_handle_cmd(android_app* app, int32_t cmd) {
Engine* engine = (Engine*)app->userData;
switch (cmd) {
case APP_CMD_INIT_WINDOW:
if (app->window != NULL)
LOGI("APP_CMD_INIT_WINDOW");
break;
case APP_CMD_TERM_WINDOW:
LOGI("APP_CMD_TERM_WINDOW");
break;

©SIProp Project, 2006-2008

17
Functions that you CAN USE
Build-in Libs: How to Use: -lxx
[NDK DIR]/platforms/android-19/arch-arm/usr/lib
libandroid.so
NativeActivity Lib

libc.so
libstdc++.so
libc

libdl.so
Dynamic Load Lib

libEGL.so
libGLESv1_CM.so
libGLESv2.so
libGLESv3.so
libjnigraphics.so

liblog.so
Logging
libm.so
Math Lib
libOpenMAXAL.so
Media Lib
libOpenSLES.so
Sound Lib
libthread_db.so
thread
libz.so
Zip Lib

Graphic Funcs
©SIProp Project, 2006-2008

18
Edit jni/Android.mk 8/8
Add Loading Lib & OpenCV Lib
LOCAL_LDLIBS
-lc -ldl -lz

LOCAL_STATIC_LIBRARIES
$(foreach mod, $(OPENCV_MODULES), opencv_$(mod))
$(OPENCV_3RDPARTY_COMPONENTS)

1. LOCAL_LDLIBS += -lm -llog -landroid -lc
-ldl -lz
2. LOCAL_STATIC_LIBRARIES :=
android_native_app_glue $(foreach mod,
$(OPENCV_MODULES), opencv_$(mod))
$(OPENCV_3RDPARTY_COMPONENTS)
©SIProp Project, 2006-2008

19
Edit jni/Android.mk 4/8
Make Loading OpenCV Libs Function
1. define add_opencv_3rdparty_component
2.
include $(CLEAR_VARS)
3.
LOCAL_MODULE:=$1
4.
LOCAL_SRC_FILES:=../../opencv2.4.7/platforms/build_android_service/3rdpar
ty/lib/armeabi-v7a/lib$1.a
5.
include $(PREBUILT_STATIC_LIBRARY)
6. endef
1. $(foreach
module,$(OPENCV_3RDPARTY_COMPONEN
TS),$(eval $(call
add_opencv_3rdparty_component,$(module))))
©SIProp Project, 2006-2008

20
Edit jni/Android.mk 6/8
Make Loading AndroidCamera Libs Function
1. define add_opencv_camera_module
2.
include $(CLEAR_VARS)
3.
LOCAL_MODULE:=$1
4.
LOCAL_SRC_FILES:=../../opencv2.4.7/platforms/build_android_service/lib/ar
meabi-v7a/lib$1.so
5.
include $(PREBUILT_SHARED_LIBRARY)
6. endef
1. $(foreach
module,$(OPENCV_CAMERA_MODULES),$(e
val $(call
add_opencv_camera_module,$(module))))
©SIProp Project, 2006-2008

21
How to Use NativeActivityGlue

©SIProp Project, 2006-2008

22
Edit AndroidManifest.xml
Replace “application” Section
1.

<application android:label="@string/app_name"
android:hasCode="false">

2.
3.
4.

<activity android:name="android.app.NativeActivity"
android:label="@string/app_name"

5.
6.
7.
8.
9.
10.
11.
12.
13.

android:configChanges="orientation|keyboardHidden">
<!-- Tell NativeActivity the name of or .so -->
<meta-data android:name="android.app.lib_name"
android:value=”SampleNativeActivity" />
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

©SIProp Project, 2006-2008

23
CPP Code of Basicary Format
1.

#include <android_native_app_glue.h>

2. void android_main() {
3.
4.
// Init Parameters
5.
6.
// Loop
7.
while(1) {
8.
9.
//Do your Program Code
10.
11.
//Drawing to Android Display
12.
13.
if(finish == TRUE) {
14.
// Processing closing
15.
return;
16.
}
17.
}
18. }
©SIProp Project, 2006-2008

24
Show Android Event
jni/SampleNativeActivity.cpp
#include <android_native_app_glue.h>
#include <android/log.h>

#define LOG_TAG "MyApp:SampleNativeActivity"
#define LOGD(...)
__android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#define LOGI(...)
__android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define LOGW(...)
__android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
#define LOGE(...)
__android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)

©SIProp Project, 2006-2008

25
Show Android Event
jni/SampleNativeActivity.cpp
struct Engine {
struct android_app* app;
};

void android_main(android_app* app) {
// Init Parameters
struct Engine engine;
// It's magic func for NativeActivityGlue.
app_dummy();
// Set UserData
memset(&engine, 0, sizeof(engine));
app->userData = &engine;

app->onAppCmd = engine_handle_cmd;
engine.app = app;
©SIProp Project, 2006-2008

26
Show Android Event
jni/SampleNativeActivity.cpp
// Loop
while(1) {
// Read all pending events.
int ident;
int events;
android_poll_source* source;
// Process system events
while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >=
0) {
// Process this event.
if (source != NULL) {
source->process(app, source);
}
//Do your Program Code
//Drawing to Android Display
}
}
}
©SIProp Project, 2006-2008

27
Show Android Event
jni/SampleNativeActivity.cpp
static void engine_handle_cmd(android_app* app, int32_t cmd) {
Engine* engine = (Engine*)app->userData;
switch (cmd) {
case APP_CMD_START:
LOGI("APP_CMD_START");
break;
case APP_CMD_RESUME:
LOGI("APP_CMD_RESUME");
break;
case APP_CMD_SAVE_STATE:
LOGI("APP_CMD_SAVE_STATE");
break;
case APP_CMD_PAUSE:
LOGI("APP_CMD_PAUSE");
break;
case APP_CMD_STOP:
LOGI("APP_CMD_STOP");
break;
case APP_CMD_DESTROY:
LOGI("APP_CMD_DESTROY");
break;

©SIProp Project, 2006-2008

28
Show Android Event
Add the Red Lines to Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := SampleNativeActivity
LOCAL_SRC_FILES := SampleNativeActivity.cpp
LOCAL_LDLIBS += -llog -landroid
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)

©SIProp Project, 2006-2008

29
©SIProp Project, 2006-2008

30
How to Draw Text

©SIProp Project, 2006-2008

31
How to Draw Text?
NDK doesn’t have this function!!!

You CAN USE Bitmap File Only!!!
Use Open GL/ES
Use OpenCV
.

©SIProp Project, 2006-2008

32
How to Draw Text with OpenCV

©SIProp Project, 2006-2008

33
Setup OpenCV Libs
Libs
libs_opencv

include Files
jni/include

©SIProp Project, 2006-2008

34
Edit jni/Android.mk 1/5
After “LOCAL_PATH := $(call my-dir)” Line

1.

include $(CLEAR_VARS)

2.

OPENCV_MODULES:=contrib legacy ml stitching objdetect
ts videostab video photo calib3d features2d highgui imgproc
flann core
OPENCV_3RDPARTY_COMPONENTS:=tbb libjpeg libpng
libtiff libjasper IlmImf

3.

©SIProp Project, 2006-2008

35
Edit jni/Android.mk 2/5

1.
2.
3.
4.
5.
6.

define add_opencv_module
include $(CLEAR_VARS)
LOCAL_MODULE:=opencv_$1
LOCAL_SRC_FILES:=../libs_opencv/libopencv_$1.a
include $(PREBUILT_STATIC_LIBRARY)
endef

7. define add_opencv_3rdparty_component
8.
include $(CLEAR_VARS)
9.
LOCAL_MODULE:=$1
10.
LOCAL_SRC_FILES:=../libs_opencv/lib$1.a
11.
include $(PREBUILT_STATIC_LIBRARY)
12. endef
©SIProp Project, 2006-2008

36
Edit jni/Android.mk 3/5

1.
2.
3.
4.

include $(CLEAR_VARS)
LOCAL_MODULE:=opencv_info
LOCAL_SRC_FILES:=../libs_opencv/libopencv_info.so
include $(PREBUILT_SHARED_LIBRARY)

5.

$(foreach module,$(OPENCV_MODULES),$(eval $(call
add_opencv_module,$(module))))
$(foreach
module,$(OPENCV_3RDPARTY_COMPONENTS),$(eval
$(call add_opencv_3rdparty_component,$(module))))

6.

©SIProp Project, 2006-2008

37
Edit jni/Android.mk 4/5

1.
2.

OPENCV_INCLUDE_DIR:=$(LOCAL_DIR)/include
LOCAL_C_INCLUDES+=$(OPENCV_INCLUDE_DIR)

©SIProp Project, 2006-2008

38
Edit jni/Android.mk 5/5
Add Loading Lib & OpenCV Lib
LOCAL_LDLIBS
-lm -lc -ldl -lz

LOCAL_STATIC_LIBRARIES
$(foreach mod, $(OPENCV_MODULES), opencv_$(mod))
$(OPENCV_3RDPARTY_COMPONENTS)

1. LOCAL_LDLIBS += -llog -landroid –lm -lc
-ldl -lz
2. LOCAL_STATIC_LIBRARIES :=
android_native_app_glue $(foreach mod,
$(OPENCV_MODULES), opencv_$(mod))
$(OPENCV_3RDPARTY_COMPONENTS)
©SIProp Project, 2006-2008

39
Application.mk
Create “Application.mk”

1.
2.
3.
4.

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-15

©SIProp Project, 2006-2008

40
SampleNativeActivity.cpp
Init Buffer
case APP_CMD_INIT_WINDOW:
LOGI("APP_CMD_INIT_WINDOW");
{
int view_width = ANativeWindow_getWidth(app->window);
int view_height = ANativeWindow_getHeight(app->window);
// Init Framebuffer
if (ANativeWindow_setBuffersGeometry(app->window,
view_width,
view_height, WINDOW_FORMAT_RGBA_8888) < 0) {
LOGE("Cannot set pixel format!");
return;
}
LOGI("cv::Mat initialized at resolution %dx%d", view_width,
view_height);
}
break;
©SIProp Project, 2006-2008

41
SampleNativeActivity.cpp
New Engine

1.
2.

struct Engine {
struct android_app* app;

3.
4.

int init_window;
};

©SIProp Project, 2006-2008

42
1.
static void engine_draw_frame(struct Engine*
SampleNativeActivity.cpp engine, const cv::Mat&
frame) {
2.
3.
4.
5.

if (engine->app->window == NULL) {
// No window.
return;
}

6.
7.
8.
9.
10.

ANativeWindow_Buffer buffer;
if (ANativeWindow_lock(engine->app->window, &buffer, NULL) < 0) {
LOGW("Unable to lock window buffer");
return;
}

11.
12.

{

13.
14.
15.
16.
17.
18.
19.
20.
21.
22.

uint16_t* pixels = (uint16_t*)buffer.bits;

for( int y = 0; y < frame.size().height; y ++ ) {
for( int x = 0; x < frame.size().width; x ++ ) {
cv::Vec3b bgr = frame.at< cv::Vec3b >( y, x );
pixels[x] = make565( bgr[2], bgr[1], bgr[0] );
}
pixels = (uint16_t*)pixels + buffer.stride;
}
}
ANativeWindow_unlockAndPost(engine->app->window);
}

©SIProp Project, 2006-2008

43
SampleNativeActivity.cpp

1.
2.
3.
4.
5.
6.

// Loop
while(1) {
// Read all pending events.
int ident;
int events;
android_poll_source* source;

7.
8.

// Process system events
while ((ident=ALooper_pollAll(0, NULL, &events,
(void**)&source)) >= 0) {
// Process this event.
if (source != NULL) {
source->process(app, source);
}
}
}

9.
10.
11.
12.
13.
14.

©SIProp Project, 2006-2008

44
SampleNativeActivity.cpp

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.

12.
13.
14.
15.

//Do your Program Code
if (engine.init_window) {
// Init Mat
int view_width = ANativeWindow_getWidth(app->window);
int view_height = ANativeWindow_getHeight(app->window);
cv::Mat img =
cv::Mat::zeros(view_width, view_height, CV_8UC3);
char buffer[256];
sprintf(buffer, "Show Display Size: %dx%d", img.cols,
img.rows);
cv::putText(img, std::string(buffer), cv::Point(256,128),
cv::FONT_HERSHEY_COMPLEX_SMALL, 1,
cv::Scalar(255,255,255));

//Drawing to Android Display
engine_draw_frame(&engine, img);
}
}
©SIProp Project, 2006-2008

45
How to Camera with OpenCV

©SIProp Project, 2006-2008

46
AndroidManifest.xml
Add “Camera” Permissions
1.

<uses-permission
android:name="android.permission.CAMERA"/>

2.

<uses-feature android:name="android.hardware.camera"
android:required="false"/>
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false"/>
<uses-feature
android:name="android.hardware.camera.front"
android:required="false"/>
<uses-feature
android:name="android.hardware.camera.front.autofocus"
android:required="false"/>

3.

4.

5.

©SIProp Project, 2006-2008

47
Edit jni/Android.mk 1/5
After “LOCAL_PATH := $(call my-dir)” Line

1.

OPENCV_CAMERA_MODULES:= native_camera_r2.2.0
native_camera_r2.3.3 native_camera_r3.0.1
native_camera_r4.0.0 native_camera_r4.0.3
native_camera_r4.1.1 native_camera_r4.2.0
native_camera_r4.3.0

1.
2.
3.
4.
5.
6.

define add_opencv_camera_module
include $(CLEAR_VARS)
LOCAL_MODULE:=$1
LOCAL_SRC_FILES:=../libs_opencv/lib$1.so
include $(PREBUILT_SHARED_LIBRARY)
endef
©SIProp Project, 2006-2008

48
Edit jni/Android.mk 3/5

1.
2.

LOCAL_SRC_FILES:=../libs_opencv/libopencv_info.so
include $(PREBUILT_SHARED_LIBRARY)

3.

$(foreach module,$(OPENCV_MODULES),$(eval $(call
add_opencv_module,$(module))))
$(foreach
module,$(OPENCV_3RDPARTY_COMPONENTS),$(eval
$(call add_opencv_3rdparty_component,$(module))))
$(foreach module,$(OPENCV_CAMERA_MODULES),$(eval
$(call add_opencv_camera_module,$(module))))

4.

5.

©SIProp Project, 2006-2008

49
case APP_CMD_INIT_WINDOW:
LOGI("APP_CMD_INIT_WINDOW");
if (app->window != NULL)
{
LOGI("APP_CMD_INIT_WINDOW");

SampleNativeActivity.cpp
Init Camera

engine->capture = new cv::VideoCapture(0);
union {double prop; const char* name;} u;
u.prop = engine->capture>get(CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING);
int view_width = ANativeWindow_getWidth(app->window);
int view_height = ANativeWindow_getHeight(app->window);
cv::Size camera_resolution;
if (u.name)
camera_resolution = calc_optimal_camera_resolution(u.name,
640, 480);
else
{
LOGE("Cannot get supported camera camera_resolutions");
camera_resolution = cv::Size(ANativeWindow_getWidth(app>window),
ANativeWindow_getHeight(app->window));
}
©SIProp Project, 2006-2008

50
SampleNativeActivity.cpp
if ((camera_resolution.width != 0) && (camera_resolution.height !=

0))

{
Init Camera
engine->capture->set(CV_CAP_PROP_FRAME_WIDTH,

camera_resolution.width);
engine->capture->set(CV_CAP_PROP_FRAME_HEIGHT,

camera_resolution.height);
}
float scale = std::min((float)view_width/camera_resolution.width,
(float)view_height/camera_resolution.height);
if (ANativeWindow_setBuffersGeometry(app->window,
(int)(view_width/scale),
int(view_height/scale), WINDOW_FORMAT_RGBA_8888) < 0)
{
LOGE("Cannot set pixel format!");
return;
}
LOGI("Camera initialized at resolution %dx%d",
camera_resolution.width, camera_resolution.height);
}
break;
©SIProp Project, 2006-2008

51
SampleNativeActivity.cpp
New Engine
1.
2.
3.
4.

struct Engine {
struct android_app* app;
cv::Ptr<cv::VideoCapture> capture;
};

©SIProp Project, 2006-2008

52
SampleNativeActivity.cpp
1.
cv::Mat drawing_frame;
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.

// Loop
while(1) {
// Read all pending events.
int ident;
int events;
android_poll_source* source;
// Process system events
while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0) {
// Process this event.
if (source != NULL) {
source->process(app, source);
}
}
//Do your Program Code
// Capture frame from camera and draw it
if (!engine.capture.empty()) {
if (engine.capture->grab())
engine.capture->retrieve(drawing_frame,
CV_CAP_ANDROID_COLOR_FRAME_RGBA);
engine_draw_frame(&engine, drawing_frame);
}
}
53
©SIProp Project, 2006-2008
How to Use Debugger

©SIProp Project, 2006-2008

54
Setup Debug Option

©SIProp Project, 2006-2008

55
Build as Debug Mode

©SIProp Project, 2006-2008

56
Enjoy Debugging!

©SIProp Project, 2006-2008

57
How to Use Profiler

©SIProp Project, 2006-2008

58
Android SDK Tools 8/12
lint
Optimize Android Applications.
lint | Android Developers
http://developer.android.com/tools/help/lint.html

©SIProp Project, 2006-2008

59
Run lint

©SIProp Project, 2006-2008

60
Android SDK Tools 6/12
hprof-conv
Convert Android Original Format Heap Memory Dump
to Standard Format. Ex. Eclipse Memory Analyzer
(MAT)
HPROF Converter | Android Developers
http://developer.android.com/tools/help/hprof-conv.html

©SIProp Project, 2006-2008

61
Setup Eclipse Memory Analyzer (MAT)

©SIProp Project, 2006-2008

62
Setup Eclipse Memory Analyzer (MAT)

©SIProp Project, 2006-2008

63
Show HeapMemory

©SIProp Project, 2006-2008

64
Add Memory Leak Code

1.
2.
3.
4.
5.
6.
7.

char *str = (char *)malloc(10000);
if(engine.counter < 65535) {
engine.leak[engine.counter] = (int)str;
LOGW("Leak Memory!!! %d", (int)str);
} else {
engine.counter = 0;
}

©SIProp Project, 2006-2008

65
But,,,Java Heap Only

©SIProp Project, 2006-2008

66
Android SDK Tools 11/12
Systrace
Profiling Tool. Use with Android Device Monitor.
Analyzing Display and Performance with Systrace | Android
Developers
http://developer.android.com/tools/debugging/systrace.html

traceview
Show Graphical View from Systrace Data
Traceview | Android Developers
http://developer.android.com/tools/help/traceview.html

deprecated
Android Device Monitor

©SIProp Project, 2006-2008

67
Systrace & TraceView

©SIProp Project, 2006-2008

68
View from Traceview

©SIProp Project, 2006-2008

69
Android SDK Tools 4/12
dmtracedump
Create Graphical Diagram from SysTrace Data
dmtracedump | Android Developers
http://developer.android.com/tools/help/dmtracedump.html

©SIProp Project, 2006-2008

70
Setup More Tools
Python
http://www.python.org/

Graphviz
http://www.graphviz.org
sudo apt-get install graphviz

©SIProp Project, 2006-2008

71
How to Use
sdk/tools
dmtracedump
-g [Graph Image Name] [Trace Data]

©SIProp Project, 2006-2008

72
sdk/platform-tools/systrace/systrace.py
Options
--time=[s]

4.2 and lower

4.3 and Upper

--list-categories
--cpu-freq
gfx - Graphics
--cpu-idle
input - Input
--cpu-load
view - View
--no-cpu-sched
webview - WebView
--set-tags=<TAGS>
wm - Window Manager
gfx - Graphics
am - Activity Manager
input - Input
audio - Audio
view - View
video - Video
webview - WebView
camera - Camera
wm - Window Manager
hal - Hardware Modules
am - Activity Manager
sync – Synchronization res - Resource Loading
dalvik - Dalvik VM
audio - Audio
rs - RenderScript
video - Video
camera - Camera

sched - CPU Scheduling
freq - CPU Frequency
membus - Memory Bus
Utilization
idle - CPU Idle
disk - Disk input and
output
load - CPU Load
sync - Synchronization
Manager
workq - Kernel
Workqueues

©SIProp Project, 2006-2008

73
How to User on 4.2
./systrace.py
--cpu-freq --cpu-idle --cpu-load --no-cpu-sched -settags=gfx,input,view,webview,wm,am,sync,audio,video,c
amera

adb shell stop
adb shell start
./systrace.py --time=10 -o mynewtrace.html

©SIProp Project, 2006-2008

74
If it doesn’t work…
Check these Configuration
kernel config
Kernel hacking ---> Tracers ---> Scheduling Latency
Tracer

init.trace.rc
mount debugfs /sys/kernel/debug /sys/kernel/debug

©SIProp Project, 2006-2008

75
Appendix

©SIProp Project, 2006-2008

76
ARM DS-5 Development Studio
Functions
Debugger for Linux/Android™/RTOS-aware
The ARM Streamline system-wide performance analyzer
Real-Time system model Simulators
All conveniently Packaged in Eclipse.
http://www.arm.com/products/tools/software-tools/ds5/index.php

©SIProp Project, 2006-2008

77
IDE

©SIProp Project, 2006-2008

78
Analyzer

©SIProp Project, 2006-2008

79

More Related Content

What's hot

Drone CI/CD Platform
Drone CI/CD PlatformDrone CI/CD Platform
Drone CI/CD PlatformBo-Yi Wu
 
Drone 1.0 Feature
Drone 1.0 FeatureDrone 1.0 Feature
Drone 1.0 FeatureBo-Yi Wu
 
Optimizing Spring Boot apps for Docker
Optimizing Spring Boot apps for DockerOptimizing Spring Boot apps for Docker
Optimizing Spring Boot apps for DockerGraham Charters
 
Deployment Patterns in the Ruby on Rails World
Deployment Patterns in the Ruby on Rails WorldDeployment Patterns in the Ruby on Rails World
Deployment Patterns in the Ruby on Rails WorldNikhil Mungel
 
GraphQL IN Golang
GraphQL IN GolangGraphQL IN Golang
GraphQL IN GolangBo-Yi Wu
 
[DEPRECATED]Gradle the android
[DEPRECATED]Gradle the android[DEPRECATED]Gradle the android
[DEPRECATED]Gradle the androidJun Liu
 
BuildKitでLazy Pullを有効にしてビルドを早くする話
BuildKitでLazy Pullを有効にしてビルドを早くする話BuildKitでLazy Pullを有効にしてビルドを早くする話
BuildKitでLazy Pullを有効にしてビルドを早くする話Kohei Tokunaga
 
Golang Project Layout and Practice
Golang Project Layout and PracticeGolang Project Layout and Practice
Golang Project Layout and PracticeBo-Yi Wu
 
Build microservice with gRPC in golang
Build microservice with gRPC in golangBuild microservice with gRPC in golang
Build microservice with gRPC in golangTing-Li Chou
 
drone continuous Integration
drone continuous Integrationdrone continuous Integration
drone continuous IntegrationBo-Yi Wu
 
Gearman work queue in php
Gearman work queue in phpGearman work queue in php
Gearman work queue in phpBo-Yi Wu
 
Ruby and Rails Packaging to Production
Ruby and Rails Packaging to ProductionRuby and Rails Packaging to Production
Ruby and Rails Packaging to ProductionFabio Kung
 
Android Jetpack + Coroutines: To infinity and beyond
Android Jetpack + Coroutines: To infinity and beyondAndroid Jetpack + Coroutines: To infinity and beyond
Android Jetpack + Coroutines: To infinity and beyondRamon Ribeiro Rabello
 
Continuous Integration & Continuous Delivery with GCP
Continuous Integration & Continuous Delivery with GCPContinuous Integration & Continuous Delivery with GCP
Continuous Integration & Continuous Delivery with GCPKAI CHU CHUNG
 
eStargzイメージとlazy pullingによる高速なコンテナ起動
eStargzイメージとlazy pullingによる高速なコンテナ起動eStargzイメージとlazy pullingによる高速なコンテナ起動
eStargzイメージとlazy pullingによる高速なコンテナ起動Kohei Tokunaga
 
Taking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the ExtremeTaking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the Extremeyinonavraham
 
Crafting Beautiful CLI Applications in Ruby
Crafting Beautiful CLI Applications in RubyCrafting Beautiful CLI Applications in Ruby
Crafting Beautiful CLI Applications in RubyNikhil Mungel
 
60分鐘完送百萬edm,背後雲端ci/cd實戰大公開
60分鐘完送百萬edm,背後雲端ci/cd實戰大公開60分鐘完送百萬edm,背後雲端ci/cd實戰大公開
60分鐘完送百萬edm,背後雲端ci/cd實戰大公開KAI CHU CHUNG
 

What's hot (20)

Drone CI/CD Platform
Drone CI/CD PlatformDrone CI/CD Platform
Drone CI/CD Platform
 
Drone 1.0 Feature
Drone 1.0 FeatureDrone 1.0 Feature
Drone 1.0 Feature
 
Optimizing Spring Boot apps for Docker
Optimizing Spring Boot apps for DockerOptimizing Spring Boot apps for Docker
Optimizing Spring Boot apps for Docker
 
Deployment Patterns in the Ruby on Rails World
Deployment Patterns in the Ruby on Rails WorldDeployment Patterns in the Ruby on Rails World
Deployment Patterns in the Ruby on Rails World
 
GraphQL IN Golang
GraphQL IN GolangGraphQL IN Golang
GraphQL IN Golang
 
Rest, sockets em golang
Rest, sockets em golangRest, sockets em golang
Rest, sockets em golang
 
[DEPRECATED]Gradle the android
[DEPRECATED]Gradle the android[DEPRECATED]Gradle the android
[DEPRECATED]Gradle the android
 
BuildKitでLazy Pullを有効にしてビルドを早くする話
BuildKitでLazy Pullを有効にしてビルドを早くする話BuildKitでLazy Pullを有効にしてビルドを早くする話
BuildKitでLazy Pullを有効にしてビルドを早くする話
 
Golang Project Layout and Practice
Golang Project Layout and PracticeGolang Project Layout and Practice
Golang Project Layout and Practice
 
Build microservice with gRPC in golang
Build microservice with gRPC in golangBuild microservice with gRPC in golang
Build microservice with gRPC in golang
 
drone continuous Integration
drone continuous Integrationdrone continuous Integration
drone continuous Integration
 
Gearman work queue in php
Gearman work queue in phpGearman work queue in php
Gearman work queue in php
 
Ruby and Rails Packaging to Production
Ruby and Rails Packaging to ProductionRuby and Rails Packaging to Production
Ruby and Rails Packaging to Production
 
Android Jetpack + Coroutines: To infinity and beyond
Android Jetpack + Coroutines: To infinity and beyondAndroid Jetpack + Coroutines: To infinity and beyond
Android Jetpack + Coroutines: To infinity and beyond
 
Continuous Integration & Continuous Delivery with GCP
Continuous Integration & Continuous Delivery with GCPContinuous Integration & Continuous Delivery with GCP
Continuous Integration & Continuous Delivery with GCP
 
Droidcon Summary 2021
Droidcon Summary 2021Droidcon Summary 2021
Droidcon Summary 2021
 
eStargzイメージとlazy pullingによる高速なコンテナ起動
eStargzイメージとlazy pullingによる高速なコンテナ起動eStargzイメージとlazy pullingによる高速なコンテナ起動
eStargzイメージとlazy pullingによる高速なコンテナ起動
 
Taking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the ExtremeTaking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the Extreme
 
Crafting Beautiful CLI Applications in Ruby
Crafting Beautiful CLI Applications in RubyCrafting Beautiful CLI Applications in Ruby
Crafting Beautiful CLI Applications in Ruby
 
60分鐘完送百萬edm,背後雲端ci/cd實戰大公開
60分鐘完送百萬edm,背後雲端ci/cd實戰大公開60分鐘完送百萬edm,背後雲端ci/cd實戰大公開
60分鐘完送百萬edm,背後雲端ci/cd實戰大公開
 

Similar to How to Make Android Native Application

7 Ways to improve your gradle build
7 Ways to improve your gradle build7 Ways to improve your gradle build
7 Ways to improve your gradle buildTania Pinheiro
 
Тестирование мобильных приложений используя облачные сервисы. TestDroid, Test...
Тестирование мобильных приложений используя облачные сервисы. TestDroid, Test...Тестирование мобильных приложений используя облачные сервисы. TestDroid, Test...
Тестирование мобильных приложений используя облачные сервисы. TestDroid, Test...COMAQA.BY
 
Native Android Development Practices
Native Android Development PracticesNative Android Development Practices
Native Android Development PracticesRoy Clarkson
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recieversUtkarsh Mankad
 
Android N Highligts
Android N HighligtsAndroid N Highligts
Android N HighligtsSercan Yusuf
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)Chiew Carol
 
Hacking the Codename One Source Code - Part IV - Transcript.pdf
Hacking the Codename One Source Code - Part IV - Transcript.pdfHacking the Codename One Source Code - Part IV - Transcript.pdf
Hacking the Codename One Source Code - Part IV - Transcript.pdfShaiAlmog1
 
The ultimate guide to optimize your react native app performance in 2022
The ultimate guide to optimize your react native app performance in 2022The ultimate guide to optimize your react native app performance in 2022
The ultimate guide to optimize your react native app performance in 2022Katy Slemon
 
Parkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_badaParkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_bada웹데브모바일
 
Learn how to develop for Android, beyond the Hello World android app - Cape T...
Learn how to develop for Android, beyond the Hello World android app - Cape T...Learn how to develop for Android, beyond the Hello World android app - Cape T...
Learn how to develop for Android, beyond the Hello World android app - Cape T...Joseph Kandi
 
From Idea to App (or “How we roll at Small Town Heroes”)
From Idea to App (or “How we roll at Small Town Heroes”)From Idea to App (or “How we roll at Small Town Heroes”)
From Idea to App (or “How we roll at Small Town Heroes”)Bramus Van Damme
 
Apache Cordova In Action
Apache Cordova In ActionApache Cordova In Action
Apache Cordova In ActionHazem Saleh
 
PhoneGap JavaScript API vs Native Components
PhoneGap JavaScript API vs Native ComponentsPhoneGap JavaScript API vs Native Components
PhoneGap JavaScript API vs Native ComponentsTechAhead
 
Native Payment - Part 2.pdf
Native Payment - Part 2.pdfNative Payment - Part 2.pdf
Native Payment - Part 2.pdfShaiAlmog1
 

Similar to How to Make Android Native Application (20)

React Native
React NativeReact Native
React Native
 
Ruby conf2012
Ruby conf2012Ruby conf2012
Ruby conf2012
 
Sst hackathon express
Sst hackathon expressSst hackathon express
Sst hackathon express
 
7 Ways to improve your gradle build
7 Ways to improve your gradle build7 Ways to improve your gradle build
7 Ways to improve your gradle build
 
Тестирование мобильных приложений используя облачные сервисы. TestDroid, Test...
Тестирование мобильных приложений используя облачные сервисы. TestDroid, Test...Тестирование мобильных приложений используя облачные сервисы. TestDroid, Test...
Тестирование мобильных приложений используя облачные сервисы. TestDroid, Test...
 
Native Android Development Practices
Native Android Development PracticesNative Android Development Practices
Native Android Development Practices
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
 
Android N Highligts
Android N HighligtsAndroid N Highligts
Android N Highligts
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)
 
Os Haase
Os HaaseOs Haase
Os Haase
 
Hacking the Codename One Source Code - Part IV - Transcript.pdf
Hacking the Codename One Source Code - Part IV - Transcript.pdfHacking the Codename One Source Code - Part IV - Transcript.pdf
Hacking the Codename One Source Code - Part IV - Transcript.pdf
 
The ultimate guide to optimize your react native app performance in 2022
The ultimate guide to optimize your react native app performance in 2022The ultimate guide to optimize your react native app performance in 2022
The ultimate guide to optimize your react native app performance in 2022
 
Parkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_badaParkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_bada
 
Nativescript with angular 2
Nativescript with angular 2Nativescript with angular 2
Nativescript with angular 2
 
Learn how to develop for Android, beyond the Hello World android app - Cape T...
Learn how to develop for Android, beyond the Hello World android app - Cape T...Learn how to develop for Android, beyond the Hello World android app - Cape T...
Learn how to develop for Android, beyond the Hello World android app - Cape T...
 
From Idea to App (or “How we roll at Small Town Heroes”)
From Idea to App (or “How we roll at Small Town Heroes”)From Idea to App (or “How we roll at Small Town Heroes”)
From Idea to App (or “How we roll at Small Town Heroes”)
 
Apache Cordova In Action
Apache Cordova In ActionApache Cordova In Action
Apache Cordova In Action
 
PhoneGap JavaScript API vs Native Components
PhoneGap JavaScript API vs Native ComponentsPhoneGap JavaScript API vs Native Components
PhoneGap JavaScript API vs Native Components
 
Native Payment - Part 2.pdf
Native Payment - Part 2.pdfNative Payment - Part 2.pdf
Native Payment - Part 2.pdf
 
OpenMIC March-2012.phonegap
OpenMIC March-2012.phonegapOpenMIC March-2012.phonegap
OpenMIC March-2012.phonegap
 

More from Industrial Technology Research Institute (ITRI)(工業技術研究院, 工研院)

More from Industrial Technology Research Institute (ITRI)(工業技術研究院, 工研院) (20)

半導体製造(TinyTapeout)に挑戦しよう!
半導体製造(TinyTapeout)に挑戦しよう!半導体製造(TinyTapeout)に挑戦しよう!
半導体製造(TinyTapeout)に挑戦しよう!
 
Introduction of ISHI-KAI with OpenMPW
Introduction of ISHI-KAI with OpenMPWIntroduction of ISHI-KAI with OpenMPW
Introduction of ISHI-KAI with OpenMPW
 
Kernel/VMレイヤーを自分色に染める!By ISHI会
Kernel/VMレイヤーを自分色に染める!By ISHI会Kernel/VMレイヤーを自分色に染める!By ISHI会
Kernel/VMレイヤーを自分色に染める!By ISHI会
 
Principle Representation of The 8 Qubits Quantum Computer by RaspberryPi
Principle Representation of The 8 Qubits Quantum Computer by RaspberryPiPrinciple Representation of The 8 Qubits Quantum Computer by RaspberryPi
Principle Representation of The 8 Qubits Quantum Computer by RaspberryPi
 
Microwaveguquantum
MicrowaveguquantumMicrowaveguquantum
Microwaveguquantum
 
The easiest way of setup QuTiP on Windows
The easiest way of setup QuTiP on WindowsThe easiest way of setup QuTiP on Windows
The easiest way of setup QuTiP on Windows
 
GNU Radio Study for Super beginner
GNU Radio Study for Super beginnerGNU Radio Study for Super beginner
GNU Radio Study for Super beginner
 
The Self-Contained SDR Satellite Grand Station with Raspberry Pi 3
The Self-Contained SDR Satellite Grand Station with Raspberry Pi 3The Self-Contained SDR Satellite Grand Station with Raspberry Pi 3
The Self-Contained SDR Satellite Grand Station with Raspberry Pi 3
 
Self‐Contained SDR Grand Station with Raspberry Pi 3
Self‐Contained SDR Grand Station with Raspberry Pi 3Self‐Contained SDR Grand Station with Raspberry Pi 3
Self‐Contained SDR Grand Station with Raspberry Pi 3
 
衛星追尾用パラボラアンテナ建設記
衛星追尾用パラボラアンテナ建設記衛星追尾用パラボラアンテナ建設記
衛星追尾用パラボラアンテナ建設記
 
All list of the measuring machines for microwave
All list of the measuring machines for microwaveAll list of the measuring machines for microwave
All list of the measuring machines for microwave
 
5000円で誰でも作れる新世代衛星地上局
5000円で誰でも作れる新世代衛星地上局5000円で誰でも作れる新世代衛星地上局
5000円で誰でも作れる新世代衛星地上局
 
How to setup mastodon in chinese
How to setup mastodon in chineseHow to setup mastodon in chinese
How to setup mastodon in chinese
 
Radiation Test -Raspberry PI Zero-
Radiation Test -Raspberry PI Zero-Radiation Test -Raspberry PI Zero-
Radiation Test -Raspberry PI Zero-
 
將DNA在廚房抽出的程序
將DNA在廚房抽出的程序將DNA在廚房抽出的程序
將DNA在廚房抽出的程序
 
Protocol of the DNA Extraction in Kitchen
Protocol of the DNA Extraction in KitchenProtocol of the DNA Extraction in Kitchen
Protocol of the DNA Extraction in Kitchen
 
3D Printed Google Cardboard for workshop
3D Printed Google Cardboard for workshop3D Printed Google Cardboard for workshop
3D Printed Google Cardboard for workshop
 
計算機(物理)
計算機(物理)計算機(物理)
計算機(物理)
 
Resume
ResumeResume
Resume
 
How to Make a Scanning Drone in Chinese
How to Make a Scanning Drone in ChineseHow to Make a Scanning Drone in Chinese
How to Make a Scanning Drone in Chinese
 

Recently uploaded

EMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? WebinarEMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? WebinarThousandEyes
 
Keep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES LiveKeep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES LiveIES VE
 
UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2DianaGray10
 
IT Service Management (ITSM) Best Practices for Advanced Computing
IT Service Management (ITSM) Best Practices for Advanced ComputingIT Service Management (ITSM) Best Practices for Advanced Computing
IT Service Management (ITSM) Best Practices for Advanced ComputingMAGNIntelligence
 
From the origin to the future of Open Source model and business
From the origin to the future of  Open Source model and businessFrom the origin to the future of  Open Source model and business
From the origin to the future of Open Source model and businessFrancesco Corti
 
.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptxHansamali Gamage
 
CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024Brian Pichman
 
Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.IPLOOK Networks
 
Top 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTop 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTopCSSGallery
 
Graphene Quantum Dots-Based Composites for Biomedical Applications
Graphene Quantum Dots-Based Composites for  Biomedical ApplicationsGraphene Quantum Dots-Based Composites for  Biomedical Applications
Graphene Quantum Dots-Based Composites for Biomedical Applicationsnooralam814309
 
LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0DanBrown980551
 
Scenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosScenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosErol GIRAUDY
 
Emil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptx
Emil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptxEmil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptx
Emil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptxNeo4j
 
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxGraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxNeo4j
 
AI Workshops at Computers In Libraries 2024
AI Workshops at Computers In Libraries 2024AI Workshops at Computers In Libraries 2024
AI Workshops at Computers In Libraries 2024Brian Pichman
 
Oracle Database 23c Security New Features.pptx
Oracle Database 23c Security New Features.pptxOracle Database 23c Security New Features.pptx
Oracle Database 23c Security New Features.pptxSatishbabu Gunukula
 
March Patch Tuesday
March Patch TuesdayMarch Patch Tuesday
March Patch TuesdayIvanti
 
Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)Muhammad Tiham Siddiqui
 
Automation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projectsAutomation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projectsDianaGray10
 

Recently uploaded (20)

EMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? WebinarEMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? Webinar
 
Keep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES LiveKeep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES Live
 
UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2
 
IT Service Management (ITSM) Best Practices for Advanced Computing
IT Service Management (ITSM) Best Practices for Advanced ComputingIT Service Management (ITSM) Best Practices for Advanced Computing
IT Service Management (ITSM) Best Practices for Advanced Computing
 
From the origin to the future of Open Source model and business
From the origin to the future of  Open Source model and businessFrom the origin to the future of  Open Source model and business
From the origin to the future of Open Source model and business
 
.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx
 
CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024
 
Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.
 
Top 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTop 10 Squarespace Development Companies
Top 10 Squarespace Development Companies
 
Graphene Quantum Dots-Based Composites for Biomedical Applications
Graphene Quantum Dots-Based Composites for  Biomedical ApplicationsGraphene Quantum Dots-Based Composites for  Biomedical Applications
Graphene Quantum Dots-Based Composites for Biomedical Applications
 
LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0
 
Scenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosScenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenarios
 
SheDev 2024
SheDev 2024SheDev 2024
SheDev 2024
 
Emil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptx
Emil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptxEmil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptx
Emil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptx
 
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxGraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
 
AI Workshops at Computers In Libraries 2024
AI Workshops at Computers In Libraries 2024AI Workshops at Computers In Libraries 2024
AI Workshops at Computers In Libraries 2024
 
Oracle Database 23c Security New Features.pptx
Oracle Database 23c Security New Features.pptxOracle Database 23c Security New Features.pptx
Oracle Database 23c Security New Features.pptx
 
March Patch Tuesday
March Patch TuesdayMarch Patch Tuesday
March Patch Tuesday
 
Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)
 
Automation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projectsAutomation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projects
 

How to Make Android Native Application

  • 1. How to Make Android Native Application Noritsuna Imamura noritsuna@siprop.org ©SIProp Project, 2006-2008 1
  • 2. Agenda How to Make NativeActivity Application NativeActivityGlue How to Draw Something How to Use Library(OpenCV) How to Debug NativeActivity Application Debug Profiling ©SIProp Project, 2006-2008 2
  • 3. How to Make Native Application with Eclipse ©SIProp Project, 2006-2008 3
  • 4. Native Application NDK wo/ADT Standard Android Application for C/C++ Only C/C++ on Limited Library Layer Call Stack APK File(Your Application) (C/C++) Advantage Only C/C++ DirectCall C/C++ API Dis-Advantage Use a few Android Tools A few Docs from Google Developer Site & Blogs Call as C/C++ APIs Library Layer (C/C++) Call as SysCall(C/ASM Kernel/Driver Layer (C/ASM)Project, 2006-2008 ©SIProp 4
  • 5. Make Android Project ©SIProp Project, 2006-2008 5
  • 6. Setup App Name & Target API ©SIProp Project, 2006-2008 6
  • 10. Android.mk 1. LOCAL_PATH := $(call my-dir) 2. include $(CLEAR_VARS) 3. LOCAL_MODULE := SampleNativeActivity 4. LOCAL_SRC_FILES := SampleNativeActivity.cpp 5. include $(BUILD_SHARED_LIBRARY) ©SIProp Project, 2006-2008 10
  • 11. LifeCycle Diagram Activity is Event Driven Arch Main Event onCreate() Start Activity Initialize Objects onStart() Finish Initialized onPause() Other Activity Start onResume() Back from Other Activity onStop() Don’t back long time ©SIProp Project, 2006-2008 11
  • 12. LifeCycle in NativeActivity [ndk dir]/platforms/android-19/archarm/usr/include/android native-activity.h 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. typedef struct ANativeActivityCallbacks { void (*onStart)(ANativeActivity* activity); void (*onResume)(ANativeActivity* activity); void* (*onSaveInstanceState)(ANativeActivity* activity, size_t* outSize); void (*onPause)(ANativeActivity* activity); void (*onStop)(ANativeActivity* activity); void (*onDestroy)(ANativeActivity* activity); ©SIProp Project, 2006-2008 12
  • 13. NativeActivity CallBacks NativeActivity Effect onStart = Activity.onStart() onResume = Activity.onResume() onSaveInstanceState = Activity.onSaveInstanceState() onPause = Activity.onPause() onStop = Activity.onStop() onDestroy = Activity.onDestroy() onWindowsFocusChanged Focus of Window was Changed onNativeWindowCreated Native Windows was Created onNativeWindowResized Native Window was Re-sized onNativeWindowRedrawNeeded Native Window was Required Re-Draw onNativeWindowDestroyed Native Window was Destroyed onInputQueueCreated InputQueue was Created onInputQueueDestroyed InputQueue was Destroyed onContentRectChanged Drawable Area was Changed (Ex.Keyboard) onConfiguratinChanged System Configuration was Changed onLowMemory System Memory was Low ©SIProp Project, 2006-2008 13
  • 14. Problem Point You MUST write it as Non-Block Function. In other word, you MUST use “Thread”. Thread Programing is sooooo hard… Why? Go to Next Page! ©SIProp Project, 2006-2008 14
  • 16. NativeActivityGlue [NDK dir]/sources/android/native_app_glue 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. void android_app_pre_exec_cmd(struct android_app* android_app, int8_t cmd) { switch (cmd) { case APP_CMD_INPUT_CHANGED: LOGV("APP_CMD_INPUT_CHANGEDn"); pthread_mutex_lock(&android_app->mutex); if (android_app->inputQueue != NULL) { AInputQueue_detachLooper(android_app->inputQueue); } android_app->inputQueue = android_app>pendingInputQueue; if (android_app->inputQueue != NULL) { LOGV("Attaching input queue to looper"); AInputQueue_attachLooper(android_app->inputQueue, android_app->looper, LOOPER_ID_INPUT, NULL, &android_app->inputPollSource); } pthread_cond_broadcast(&android_app->cond); pthread_mutex_unlock(&android_app->mutex); break; ©SIProp Project, 2006-2008 16
  • 17. Sample of NativeActivityGlue Don’t Need to Use “thread” Funcs. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. static void engine_handle_cmd(android_app* app, int32_t cmd) { Engine* engine = (Engine*)app->userData; switch (cmd) { case APP_CMD_INIT_WINDOW: if (app->window != NULL) LOGI("APP_CMD_INIT_WINDOW"); break; case APP_CMD_TERM_WINDOW: LOGI("APP_CMD_TERM_WINDOW"); break; ©SIProp Project, 2006-2008 17
  • 18. Functions that you CAN USE Build-in Libs: How to Use: -lxx [NDK DIR]/platforms/android-19/arch-arm/usr/lib libandroid.so NativeActivity Lib libc.so libstdc++.so libc libdl.so Dynamic Load Lib libEGL.so libGLESv1_CM.so libGLESv2.so libGLESv3.so libjnigraphics.so liblog.so Logging libm.so Math Lib libOpenMAXAL.so Media Lib libOpenSLES.so Sound Lib libthread_db.so thread libz.so Zip Lib Graphic Funcs ©SIProp Project, 2006-2008 18
  • 19. Edit jni/Android.mk 8/8 Add Loading Lib & OpenCV Lib LOCAL_LDLIBS -lc -ldl -lz LOCAL_STATIC_LIBRARIES $(foreach mod, $(OPENCV_MODULES), opencv_$(mod)) $(OPENCV_3RDPARTY_COMPONENTS) 1. LOCAL_LDLIBS += -lm -llog -landroid -lc -ldl -lz 2. LOCAL_STATIC_LIBRARIES := android_native_app_glue $(foreach mod, $(OPENCV_MODULES), opencv_$(mod)) $(OPENCV_3RDPARTY_COMPONENTS) ©SIProp Project, 2006-2008 19
  • 20. Edit jni/Android.mk 4/8 Make Loading OpenCV Libs Function 1. define add_opencv_3rdparty_component 2. include $(CLEAR_VARS) 3. LOCAL_MODULE:=$1 4. LOCAL_SRC_FILES:=../../opencv2.4.7/platforms/build_android_service/3rdpar ty/lib/armeabi-v7a/lib$1.a 5. include $(PREBUILT_STATIC_LIBRARY) 6. endef 1. $(foreach module,$(OPENCV_3RDPARTY_COMPONEN TS),$(eval $(call add_opencv_3rdparty_component,$(module)))) ©SIProp Project, 2006-2008 20
  • 21. Edit jni/Android.mk 6/8 Make Loading AndroidCamera Libs Function 1. define add_opencv_camera_module 2. include $(CLEAR_VARS) 3. LOCAL_MODULE:=$1 4. LOCAL_SRC_FILES:=../../opencv2.4.7/platforms/build_android_service/lib/ar meabi-v7a/lib$1.so 5. include $(PREBUILT_SHARED_LIBRARY) 6. endef 1. $(foreach module,$(OPENCV_CAMERA_MODULES),$(e val $(call add_opencv_camera_module,$(module)))) ©SIProp Project, 2006-2008 21
  • 22. How to Use NativeActivityGlue ©SIProp Project, 2006-2008 22
  • 23. Edit AndroidManifest.xml Replace “application” Section 1. <application android:label="@string/app_name" android:hasCode="false"> 2. 3. 4. <activity android:name="android.app.NativeActivity" android:label="@string/app_name" 5. 6. 7. 8. 9. 10. 11. 12. 13. android:configChanges="orientation|keyboardHidden"> <!-- Tell NativeActivity the name of or .so --> <meta-data android:name="android.app.lib_name" android:value=”SampleNativeActivity" /> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> ©SIProp Project, 2006-2008 23
  • 24. CPP Code of Basicary Format 1. #include <android_native_app_glue.h> 2. void android_main() { 3. 4. // Init Parameters 5. 6. // Loop 7. while(1) { 8. 9. //Do your Program Code 10. 11. //Drawing to Android Display 12. 13. if(finish == TRUE) { 14. // Processing closing 15. return; 16. } 17. } 18. } ©SIProp Project, 2006-2008 24
  • 25. Show Android Event jni/SampleNativeActivity.cpp #include <android_native_app_glue.h> #include <android/log.h> #define LOG_TAG "MyApp:SampleNativeActivity" #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) #define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__) #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) ©SIProp Project, 2006-2008 25
  • 26. Show Android Event jni/SampleNativeActivity.cpp struct Engine { struct android_app* app; }; void android_main(android_app* app) { // Init Parameters struct Engine engine; // It's magic func for NativeActivityGlue. app_dummy(); // Set UserData memset(&engine, 0, sizeof(engine)); app->userData = &engine; app->onAppCmd = engine_handle_cmd; engine.app = app; ©SIProp Project, 2006-2008 26
  • 27. Show Android Event jni/SampleNativeActivity.cpp // Loop while(1) { // Read all pending events. int ident; int events; android_poll_source* source; // Process system events while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0) { // Process this event. if (source != NULL) { source->process(app, source); } //Do your Program Code //Drawing to Android Display } } } ©SIProp Project, 2006-2008 27
  • 28. Show Android Event jni/SampleNativeActivity.cpp static void engine_handle_cmd(android_app* app, int32_t cmd) { Engine* engine = (Engine*)app->userData; switch (cmd) { case APP_CMD_START: LOGI("APP_CMD_START"); break; case APP_CMD_RESUME: LOGI("APP_CMD_RESUME"); break; case APP_CMD_SAVE_STATE: LOGI("APP_CMD_SAVE_STATE"); break; case APP_CMD_PAUSE: LOGI("APP_CMD_PAUSE"); break; case APP_CMD_STOP: LOGI("APP_CMD_STOP"); break; case APP_CMD_DESTROY: LOGI("APP_CMD_DESTROY"); break; ©SIProp Project, 2006-2008 28
  • 29. Show Android Event Add the Red Lines to Android.mk LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := SampleNativeActivity LOCAL_SRC_FILES := SampleNativeActivity.cpp LOCAL_LDLIBS += -llog -landroid LOCAL_STATIC_LIBRARIES := android_native_app_glue include $(BUILD_SHARED_LIBRARY) $(call import-module,android/native_app_glue) ©SIProp Project, 2006-2008 29
  • 31. How to Draw Text ©SIProp Project, 2006-2008 31
  • 32. How to Draw Text? NDK doesn’t have this function!!! You CAN USE Bitmap File Only!!! Use Open GL/ES Use OpenCV . ©SIProp Project, 2006-2008 32
  • 33. How to Draw Text with OpenCV ©SIProp Project, 2006-2008 33
  • 34. Setup OpenCV Libs Libs libs_opencv include Files jni/include ©SIProp Project, 2006-2008 34
  • 35. Edit jni/Android.mk 1/5 After “LOCAL_PATH := $(call my-dir)” Line 1. include $(CLEAR_VARS) 2. OPENCV_MODULES:=contrib legacy ml stitching objdetect ts videostab video photo calib3d features2d highgui imgproc flann core OPENCV_3RDPARTY_COMPONENTS:=tbb libjpeg libpng libtiff libjasper IlmImf 3. ©SIProp Project, 2006-2008 35
  • 36. Edit jni/Android.mk 2/5 1. 2. 3. 4. 5. 6. define add_opencv_module include $(CLEAR_VARS) LOCAL_MODULE:=opencv_$1 LOCAL_SRC_FILES:=../libs_opencv/libopencv_$1.a include $(PREBUILT_STATIC_LIBRARY) endef 7. define add_opencv_3rdparty_component 8. include $(CLEAR_VARS) 9. LOCAL_MODULE:=$1 10. LOCAL_SRC_FILES:=../libs_opencv/lib$1.a 11. include $(PREBUILT_STATIC_LIBRARY) 12. endef ©SIProp Project, 2006-2008 36
  • 37. Edit jni/Android.mk 3/5 1. 2. 3. 4. include $(CLEAR_VARS) LOCAL_MODULE:=opencv_info LOCAL_SRC_FILES:=../libs_opencv/libopencv_info.so include $(PREBUILT_SHARED_LIBRARY) 5. $(foreach module,$(OPENCV_MODULES),$(eval $(call add_opencv_module,$(module)))) $(foreach module,$(OPENCV_3RDPARTY_COMPONENTS),$(eval $(call add_opencv_3rdparty_component,$(module)))) 6. ©SIProp Project, 2006-2008 37
  • 39. Edit jni/Android.mk 5/5 Add Loading Lib & OpenCV Lib LOCAL_LDLIBS -lm -lc -ldl -lz LOCAL_STATIC_LIBRARIES $(foreach mod, $(OPENCV_MODULES), opencv_$(mod)) $(OPENCV_3RDPARTY_COMPONENTS) 1. LOCAL_LDLIBS += -llog -landroid –lm -lc -ldl -lz 2. LOCAL_STATIC_LIBRARIES := android_native_app_glue $(foreach mod, $(OPENCV_MODULES), opencv_$(mod)) $(OPENCV_3RDPARTY_COMPONENTS) ©SIProp Project, 2006-2008 39
  • 40. Application.mk Create “Application.mk” 1. 2. 3. 4. APP_STL := gnustl_static APP_CPPFLAGS := -frtti -fexceptions APP_ABI := armeabi-v7a APP_PLATFORM := android-15 ©SIProp Project, 2006-2008 40
  • 41. SampleNativeActivity.cpp Init Buffer case APP_CMD_INIT_WINDOW: LOGI("APP_CMD_INIT_WINDOW"); { int view_width = ANativeWindow_getWidth(app->window); int view_height = ANativeWindow_getHeight(app->window); // Init Framebuffer if (ANativeWindow_setBuffersGeometry(app->window, view_width, view_height, WINDOW_FORMAT_RGBA_8888) < 0) { LOGE("Cannot set pixel format!"); return; } LOGI("cv::Mat initialized at resolution %dx%d", view_width, view_height); } break; ©SIProp Project, 2006-2008 41
  • 42. SampleNativeActivity.cpp New Engine 1. 2. struct Engine { struct android_app* app; 3. 4. int init_window; }; ©SIProp Project, 2006-2008 42
  • 43. 1. static void engine_draw_frame(struct Engine* SampleNativeActivity.cpp engine, const cv::Mat& frame) { 2. 3. 4. 5. if (engine->app->window == NULL) { // No window. return; } 6. 7. 8. 9. 10. ANativeWindow_Buffer buffer; if (ANativeWindow_lock(engine->app->window, &buffer, NULL) < 0) { LOGW("Unable to lock window buffer"); return; } 11. 12. { 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. uint16_t* pixels = (uint16_t*)buffer.bits; for( int y = 0; y < frame.size().height; y ++ ) { for( int x = 0; x < frame.size().width; x ++ ) { cv::Vec3b bgr = frame.at< cv::Vec3b >( y, x ); pixels[x] = make565( bgr[2], bgr[1], bgr[0] ); } pixels = (uint16_t*)pixels + buffer.stride; } } ANativeWindow_unlockAndPost(engine->app->window); } ©SIProp Project, 2006-2008 43
  • 44. SampleNativeActivity.cpp 1. 2. 3. 4. 5. 6. // Loop while(1) { // Read all pending events. int ident; int events; android_poll_source* source; 7. 8. // Process system events while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0) { // Process this event. if (source != NULL) { source->process(app, source); } } } 9. 10. 11. 12. 13. 14. ©SIProp Project, 2006-2008 44
  • 45. SampleNativeActivity.cpp 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. //Do your Program Code if (engine.init_window) { // Init Mat int view_width = ANativeWindow_getWidth(app->window); int view_height = ANativeWindow_getHeight(app->window); cv::Mat img = cv::Mat::zeros(view_width, view_height, CV_8UC3); char buffer[256]; sprintf(buffer, "Show Display Size: %dx%d", img.cols, img.rows); cv::putText(img, std::string(buffer), cv::Point(256,128), cv::FONT_HERSHEY_COMPLEX_SMALL, 1, cv::Scalar(255,255,255)); //Drawing to Android Display engine_draw_frame(&engine, img); } } ©SIProp Project, 2006-2008 45
  • 46. How to Camera with OpenCV ©SIProp Project, 2006-2008 46
  • 47. AndroidManifest.xml Add “Camera” Permissions 1. <uses-permission android:name="android.permission.CAMERA"/> 2. <uses-feature android:name="android.hardware.camera" android:required="false"/> <uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/> <uses-feature android:name="android.hardware.camera.front" android:required="false"/> <uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/> 3. 4. 5. ©SIProp Project, 2006-2008 47
  • 48. Edit jni/Android.mk 1/5 After “LOCAL_PATH := $(call my-dir)” Line 1. OPENCV_CAMERA_MODULES:= native_camera_r2.2.0 native_camera_r2.3.3 native_camera_r3.0.1 native_camera_r4.0.0 native_camera_r4.0.3 native_camera_r4.1.1 native_camera_r4.2.0 native_camera_r4.3.0 1. 2. 3. 4. 5. 6. define add_opencv_camera_module include $(CLEAR_VARS) LOCAL_MODULE:=$1 LOCAL_SRC_FILES:=../libs_opencv/lib$1.so include $(PREBUILT_SHARED_LIBRARY) endef ©SIProp Project, 2006-2008 48
  • 49. Edit jni/Android.mk 3/5 1. 2. LOCAL_SRC_FILES:=../libs_opencv/libopencv_info.so include $(PREBUILT_SHARED_LIBRARY) 3. $(foreach module,$(OPENCV_MODULES),$(eval $(call add_opencv_module,$(module)))) $(foreach module,$(OPENCV_3RDPARTY_COMPONENTS),$(eval $(call add_opencv_3rdparty_component,$(module)))) $(foreach module,$(OPENCV_CAMERA_MODULES),$(eval $(call add_opencv_camera_module,$(module)))) 4. 5. ©SIProp Project, 2006-2008 49
  • 50. case APP_CMD_INIT_WINDOW: LOGI("APP_CMD_INIT_WINDOW"); if (app->window != NULL) { LOGI("APP_CMD_INIT_WINDOW"); SampleNativeActivity.cpp Init Camera engine->capture = new cv::VideoCapture(0); union {double prop; const char* name;} u; u.prop = engine->capture>get(CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING); int view_width = ANativeWindow_getWidth(app->window); int view_height = ANativeWindow_getHeight(app->window); cv::Size camera_resolution; if (u.name) camera_resolution = calc_optimal_camera_resolution(u.name, 640, 480); else { LOGE("Cannot get supported camera camera_resolutions"); camera_resolution = cv::Size(ANativeWindow_getWidth(app>window), ANativeWindow_getHeight(app->window)); } ©SIProp Project, 2006-2008 50
  • 51. SampleNativeActivity.cpp if ((camera_resolution.width != 0) && (camera_resolution.height != 0)) { Init Camera engine->capture->set(CV_CAP_PROP_FRAME_WIDTH, camera_resolution.width); engine->capture->set(CV_CAP_PROP_FRAME_HEIGHT, camera_resolution.height); } float scale = std::min((float)view_width/camera_resolution.width, (float)view_height/camera_resolution.height); if (ANativeWindow_setBuffersGeometry(app->window, (int)(view_width/scale), int(view_height/scale), WINDOW_FORMAT_RGBA_8888) < 0) { LOGE("Cannot set pixel format!"); return; } LOGI("Camera initialized at resolution %dx%d", camera_resolution.width, camera_resolution.height); } break; ©SIProp Project, 2006-2008 51
  • 52. SampleNativeActivity.cpp New Engine 1. 2. 3. 4. struct Engine { struct android_app* app; cv::Ptr<cv::VideoCapture> capture; }; ©SIProp Project, 2006-2008 52
  • 53. SampleNativeActivity.cpp 1. cv::Mat drawing_frame; 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. // Loop while(1) { // Read all pending events. int ident; int events; android_poll_source* source; // Process system events while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0) { // Process this event. if (source != NULL) { source->process(app, source); } } //Do your Program Code // Capture frame from camera and draw it if (!engine.capture.empty()) { if (engine.capture->grab()) engine.capture->retrieve(drawing_frame, CV_CAP_ANDROID_COLOR_FRAME_RGBA); engine_draw_frame(&engine, drawing_frame); } } 53 ©SIProp Project, 2006-2008
  • 54. How to Use Debugger ©SIProp Project, 2006-2008 54
  • 55. Setup Debug Option ©SIProp Project, 2006-2008 55
  • 56. Build as Debug Mode ©SIProp Project, 2006-2008 56
  • 58. How to Use Profiler ©SIProp Project, 2006-2008 58
  • 59. Android SDK Tools 8/12 lint Optimize Android Applications. lint | Android Developers http://developer.android.com/tools/help/lint.html ©SIProp Project, 2006-2008 59
  • 61. Android SDK Tools 6/12 hprof-conv Convert Android Original Format Heap Memory Dump to Standard Format. Ex. Eclipse Memory Analyzer (MAT) HPROF Converter | Android Developers http://developer.android.com/tools/help/hprof-conv.html ©SIProp Project, 2006-2008 61
  • 62. Setup Eclipse Memory Analyzer (MAT) ©SIProp Project, 2006-2008 62
  • 63. Setup Eclipse Memory Analyzer (MAT) ©SIProp Project, 2006-2008 63
  • 65. Add Memory Leak Code 1. 2. 3. 4. 5. 6. 7. char *str = (char *)malloc(10000); if(engine.counter < 65535) { engine.leak[engine.counter] = (int)str; LOGW("Leak Memory!!! %d", (int)str); } else { engine.counter = 0; } ©SIProp Project, 2006-2008 65
  • 66. But,,,Java Heap Only ©SIProp Project, 2006-2008 66
  • 67. Android SDK Tools 11/12 Systrace Profiling Tool. Use with Android Device Monitor. Analyzing Display and Performance with Systrace | Android Developers http://developer.android.com/tools/debugging/systrace.html traceview Show Graphical View from Systrace Data Traceview | Android Developers http://developer.android.com/tools/help/traceview.html deprecated Android Device Monitor ©SIProp Project, 2006-2008 67
  • 68. Systrace & TraceView ©SIProp Project, 2006-2008 68
  • 69. View from Traceview ©SIProp Project, 2006-2008 69
  • 70. Android SDK Tools 4/12 dmtracedump Create Graphical Diagram from SysTrace Data dmtracedump | Android Developers http://developer.android.com/tools/help/dmtracedump.html ©SIProp Project, 2006-2008 70
  • 71. Setup More Tools Python http://www.python.org/ Graphviz http://www.graphviz.org sudo apt-get install graphviz ©SIProp Project, 2006-2008 71
  • 72. How to Use sdk/tools dmtracedump -g [Graph Image Name] [Trace Data] ©SIProp Project, 2006-2008 72
  • 73. sdk/platform-tools/systrace/systrace.py Options --time=[s] 4.2 and lower 4.3 and Upper --list-categories --cpu-freq gfx - Graphics --cpu-idle input - Input --cpu-load view - View --no-cpu-sched webview - WebView --set-tags=<TAGS> wm - Window Manager gfx - Graphics am - Activity Manager input - Input audio - Audio view - View video - Video webview - WebView camera - Camera wm - Window Manager hal - Hardware Modules am - Activity Manager sync – Synchronization res - Resource Loading dalvik - Dalvik VM audio - Audio rs - RenderScript video - Video camera - Camera sched - CPU Scheduling freq - CPU Frequency membus - Memory Bus Utilization idle - CPU Idle disk - Disk input and output load - CPU Load sync - Synchronization Manager workq - Kernel Workqueues ©SIProp Project, 2006-2008 73
  • 74. How to User on 4.2 ./systrace.py --cpu-freq --cpu-idle --cpu-load --no-cpu-sched -settags=gfx,input,view,webview,wm,am,sync,audio,video,c amera adb shell stop adb shell start ./systrace.py --time=10 -o mynewtrace.html ©SIProp Project, 2006-2008 74
  • 75. If it doesn’t work… Check these Configuration kernel config Kernel hacking ---> Tracers ---> Scheduling Latency Tracer init.trace.rc mount debugfs /sys/kernel/debug /sys/kernel/debug ©SIProp Project, 2006-2008 75
  • 77. ARM DS-5 Development Studio Functions Debugger for Linux/Android™/RTOS-aware The ARM Streamline system-wide performance analyzer Real-Time system model Simulators All conveniently Packaged in Eclipse. http://www.arm.com/products/tools/software-tools/ds5/index.php ©SIProp Project, 2006-2008 77