用 NDK編譯Graphite2

Graphite is a "smart font" system developed specifically to handle the complexities of lesser-known languages of the world. php

上面這段話是從Graphite的官網(http://scripts.sil.org/cms/scripts/page.php?site_id=projects&item_id=graphite_hom)上摘的對於這個Open Source library的功能的描述。它是一個相似於Harfbuzz的一個文本shape的引擎,只不過,它在shape的過程當中,會更加依賴於font文件中提供的信息。對於緬甸語的處理,Graphite引擎 + Padauk font 文件的組合方案,堪稱完美。 html

這個library用到的API也大多在standard C++的範圍以內,這就給用NDK編譯這個library創造了很好的條件。 linux

在NDK中使用STL的方法,能夠看到Google官方文檔(prebuilts/ndk/7/sources/cxx-stl/gnu-libstdc++/README)中的一段話: android

This directory contains the headers and prebuilt binaries for the
GNU libstdc++-v3 C++ Standard Template Library implementation.

These are generated from the toolchain sources by the rebuild-all-prebuilt.sh
script under build/tools.

To use it, define APP_STL to 'gnustl_static' in your Application.mk.
See docs/CPLUSPLUS-SUPPORT.html for more details.

This implementation fully supports C++ exceptions and RTTI.
這段文字中提到的 Application.mk的含義是,須要在jni這個folder下原來的那個Android.mk文件的基礎之上,添加另外的一個名爲 Application.mk的文件。在咱們爲了編譯graphite2而添加的 Application.mk文件中,實際上能夠只有一句話:
APP_STL := gnustl_static

編譯這種module的另外的一個麻煩之處是,咱們沒有辦法一會兒看出來,到底須要往咱們的source file list中添加多少個source file。大概只能經過逐個的添加文件,直到在也不會爆出「Undefined reference to ...」 這種build error的信息爲止了吧。以下的Android.mk 文件是通過反覆的連接報錯->添加source file這樣一個過程,所獲得的結果。 c++

# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

HOME := /media/hanpfei

ANDROID_SOURCE_TOP=$(HOME)/LinData/android_src/JellyBean

LOCAL_MODULE    := hello-jni
LOCAL_SRC_FILES := hello-jni.cpp \
                   JniHelper.cpp\
                   JniDebug.cpp

LOCAL_LDLIBS    := -llog

include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE    := graphite2

LOCAL_SRC_FILES := graphite2-1.2.0/src/Bidi.cpp \
                   graphite2-1.2.0/src/CachedFace.cpp \
                   graphite2-1.2.0/src/call_machine.cpp \
                   graphite2-1.2.0/src/CmapCache.cpp \
                   graphite2-1.2.0/src/Code.cpp \
                   graphite2-1.2.0/src/Face.cpp \
                   graphite2-1.2.0/src/FeatureMap.cpp \
                   graphite2-1.2.0/src/FileFace.cpp \
                   graphite2-1.2.0/src/Font.cpp \
                   graphite2-1.2.0/src/GlyphCache.cpp \
                   graphite2-1.2.0/src/GlyphFace.cpp \
                   graphite2-1.2.0/src/gr_face.cpp \
                   graphite2-1.2.0/src/gr_font.cpp \
                   graphite2-1.2.0/src/gr_logging.cpp \
                   graphite2-1.2.0/src/gr_slot.cpp \
                   graphite2-1.2.0/src/json.cpp \
                   graphite2-1.2.0/src/NameTable.cpp \
                   graphite2-1.2.0/src/Pass.cpp \
                   graphite2-1.2.0/src/SegCache.cpp \
                   graphite2-1.2.0/src/SegCacheEntry.cpp \
                   graphite2-1.2.0/src/SegCacheStore.cpp \
                   graphite2-1.2.0/src/Segment.cpp \
                   graphite2-1.2.0/src/Silf.cpp \
                   graphite2-1.2.0/src/Slot.cpp \
                   graphite2-1.2.0/src/Sparse.cpp \
                   graphite2-1.2.0/src/TtfUtil.cpp \
                   graphite2-1.2.0/src/UtfCodec.cpp

LOCAL_C_INCLUDES += \
        $(LOCAL_PATH)/graphite2-1.2.0/src \
        $(LOCAL_PATH)/graphite2-1.2.0/include

include $(BUILD_SHARED_LIBRARY)

這個Android.mk文件中,另外一個值得咱們參考的是,在同一個mk文件中,定義對於兩個library的編譯的方法。我的認爲,比較關鍵的地方在於,include $(CLEAR_VARS) 這一行。它的含義大致上是將前面定義的全部的變量都給清除掉。這樣大概就能夠讓咱們很方便的將多個Android.mk文件給合併成爲一個了。 shell

執行ndk-build,輸出大概就會像下面這樣: express

hanpfei@ubuntu:/media/hanpfei/LinData/workspace/Graphite-jni$ ndk-build 
/home/hanpfei/Data/Tools/android-ndk-r8d/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 3 in ./AndroidManifest.xml    
Gdbserver      : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
Gdbsetup       : libs/armeabi/gdb.setup
Compile++ thumb  : graphite2 <= Bidi.cpp
Compile++ thumb  : graphite2 <= CachedFace.cpp
Compile++ thumb  : graphite2 <= call_machine.cpp
Compile++ thumb  : graphite2 <= CmapCache.cpp
Compile++ thumb  : graphite2 <= Code.cpp
Compile++ thumb  : graphite2 <= Face.cpp
Compile++ thumb  : graphite2 <= FeatureMap.cpp
Compile++ thumb  : graphite2 <= FileFace.cpp
Compile++ thumb  : graphite2 <= Font.cpp
Compile++ thumb  : graphite2 <= GlyphCache.cpp
Compile++ thumb  : graphite2 <= GlyphFace.cpp
Compile++ thumb  : graphite2 <= gr_face.cpp
Compile++ thumb  : graphite2 <= gr_font.cpp
Compile++ thumb  : graphite2 <= gr_logging.cpp
Compile++ thumb  : graphite2 <= gr_slot.cpp
Compile++ thumb  : graphite2 <= json.cpp
Compile++ thumb  : graphite2 <= NameTable.cpp
Compile++ thumb  : graphite2 <= Pass.cpp
Compile++ thumb  : graphite2 <= SegCache.cpp
Compile++ thumb  : graphite2 <= SegCacheEntry.cpp
Compile++ thumb  : graphite2 <= SegCacheStore.cpp
Compile++ thumb  : graphite2 <= Segment.cpp
Compile++ thumb  : graphite2 <= Silf.cpp
Compile++ thumb  : graphite2 <= Slot.cpp
Compile++ thumb  : graphite2 <= Sparse.cpp
Compile++ thumb  : graphite2 <= TtfUtil.cpp
Compile++ thumb  : graphite2 <= UtfCodec.cpp
SharedLibrary  : libgraphite2.so
Install        : libgraphite2.so => libs/armeabi/libgraphite2.so
Compile++ thumb  : hello-jni <= hello-jni.cpp
Compile++ thumb  : hello-jni <= JniHelper.cpp
Compile++ thumb  : hello-jni <= JniDebug.cpp
SharedLibrary  : libhello-jni.so
Install        : libhello-jni.so => libs/armeabi/libhello-jni.so

End apache

相關文章
相關標籤/搜索