Android NDK – hello catcake

catcake version

catcake-0.9.5-src.tar.gz

 

Build catcake into a static library with Android NDK

After downloaded the package, then un-zip it into a workspace folder as you wish. To make some work become more easy, I added a env variable named “CATCAKE_ROOT”to point out where my catcake root folder is.

The fist thing that we need to do is to build the catcake project into a static library, so that any other samples could re-use it without need to rebuild it.

To build the static library with Android NDk, I created a file “Application.mk”under $(CATCAKE_ROOT)\project\android\jni.

Application.mk

APP_MODULES      := catcake
APP_PLATFORM     := android-10

For file “Android.mk”(located in the same folder), I modified “LOCAL_C_INCLUDES”part.

LOCAL_C_INCLUDES before modification

LOCAL_C_INCLUDES := \
    apps/catcake/include \
    apps/catcake/source \
    apps/catcake/project/include/zlib \
    apps/catcake/project/include/libpng \
    apps/catcake/project/include/freetype

LOCAL_C_INCLUDES after modification

LOCAL_C_INCLUDES += $(CATCAKE_ROOT)/include
LOCAL_C_INCLUDES += $(CATCAKE_ROOT)/source
LOCAL_C_INCLUDES += $(CATCAKE_ROOT)/project/include/zlib
LOCAL_C_INCLUDES += $(CATCAKE_ROOT)/project/include/libpng
LOCAL_C_INCLUDES += $(CATCAKE_ROOT)/project/include/freetype

 

Then switch to folder $(CATCAKE_ROOT)\project\android, type in:

> ndk-build –B

If you see something like this, that means you have already successfully build the catcake static library.

build-catcake

 

The you need to copy following libraries into $(CATCAKE_ROOT)\lib

$(CATCAKE_ROOT)\project\android\obj\local\armeabi\libcatcake.a

$(CATCAKE_ROOT)\project\lib\libfreetype.a libpng.a libz.a

 

Build hello_catcake sample with NDK

Now that you already have the libcatcake.a file, you could continue the hello_catcake sample. You could find hello_catcake under $(CATCAKE_ROOT)\sample\project\hello_catcake folder. Modify the Android.mk as following to let sample use libcatcake.a and find the header files and other libraries in the correct location.

Android.mk

复制代码
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := static_catcake
LOCAL_SRC_FILES := ../../../../../lib/libcatcake.a
# LOCAL_EXPORT_C_INCLUDES := $(CATCAKE_ROOT)/include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := hello_catcake
LOCAL_SRC_FILES := main.cpp hello_catcake.cpp 
LOCAL_C_INCLUDES := $(CATCAKE_ROOT)/include
LOCAL_CXXFLAGS := -DNDEBUG -DCK_ANDROID
LOCAL_LDLIBS := -L$(CATCAKE_ROOT)/lib -lfreetype -lpng -lz -lGLESv1_CM -lgcc
LOCAL_STATIC_LIBRARIES := static_catcake

include $(BUILD_SHARED_LIBRARY)
复制代码

If the build process goes smoothly, you will see the information like the following diagram:build_hello_catcake

 

Android platform version setting up

One thing that you need to take care about is the Android platform version setting up. There are some place that could set this value, so please make sure all of them use a consistent value.

Application.mk => APP_PLATFORM     := android-10

default.properties => target=android-10

project.properties => target=android-15 # eclipse project setting

AndroidManifest.xml => <uses-sdk android:minSdkVersion="10" /> # eclipse project setting

 

Run hello_catcake from Eclipse

Now you could import the hello_catcake sample into the eclipse, then “Run”-> “Run As Android Application”.

The first time, you run the application, you need to push the application data to emulator with adb push command. This already mentioned in the source code comment part.

复制代码
ckCreateCatcake("Hello Catcake", 320, 480, 30);

    /*
        The resource files need to be copied to the target by using 'adb push' command like this:
            adb push hello_catcake/data /data/data/catcake_application.hello_catcake/data

        And they must be specified by the absolute paths in ckResMgr::loadResource.
    */
    ckResMgr::loadResource("/data/data/catcake_application.hello_catcake/data/catcake_logo_71x14.png", true);
    ckResMgr::loadResource("/data/data/catcake_application.hello_catcake/data/stonsans.ttf", true);

    newHelloCatcake();
复制代码

When one of your emulator launched, then try to push those data to emulator.

> adb push hello_catcake/data /data/data/catcake_application.hello_catcake/data

Now re-launch the application, you should see a diagram like this:

run_hello_catcake

There must be some view port setting problem. Need to check later.

 

Reference

http://kingj.iteye.com/blog/1533487

posted @   opencoder  阅读(758)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示