Click here to Skip to main content
15,867,771 members
Articles / Mobile Apps / Android
Article

Building FreeType Libraries for x86 Devices Using the Android NDK

14 Jan 2016CPOL4 min read 18.4K   5  
In this document, we’ll describe how to configure Eclipse to set up an automatic NDK build for FreeType.

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

Intel® Developer Zone offers tools and how-to information for cross-platform app development, platform and technology information, code samples, and peer expertise to help developers innovate and succeed. Join our communities for Android, Internet of Things, Intel® RealSense™ Technology and Windows to download tools, access dev kits, share ideas with like-minded developers, and participate in hackathon’s, contests, roadshows, and local events.

FreeType is a font service middleware that is written in industry-standard ANSI C. It comes with the build system that is based on GNU Make. The native development kit (NDK) is a toolset that allows you to implement C and C++ in Android apps, auto-generate project and build files, build native libraries, copy the libraries into appropriate folders, and more. For more information on the NDK, see http://developer.android.com/tools/sdk/ndk/index.html. To download and install the latest NDK build, go to http://developer.android.com/ndk/downloads/index.html.

There are many ways to build middleware libraries. You can compile middleware using an automatic NDK build system. Alternatively, you can cross-compile middleware from Cygwin* using the standalone toolchain option. For the list of some Android* middleware libraries that support x86, visit https://software.intel.com/en-us/blogs/2015/06/26/building-android-middleware-libraries-for-x86-devices-using-the-android-ndk. In this document, we’ll describe how to configure Eclipse* to set up an automatic NDK build for FreeType.

Creating a New Android* Application Project in Eclipse

For detailed instruction of how to create a new Android application project in Eclipse*, see http://developer.android.com/tools/projects/projects-eclipse.html. After you have created a new Android* application project, create a “jni” folder inside the Android project as shown below:

Image 1

Figure 1: Create a jni folder

Downloading the FreeType Library

To download the latest FreeType middleware, browse to http://sourceforge.net/projects/freetype/files/freetype2. As of this writing, the latest FreeType version is 2.6. Change to the jni directory, and untar the freetype-2.6.tar.gz using a cgwin or Linux* console.

Image 2

Figure 2: FreeType source files under the jni folder

Adding Android.mk and Application.mk into the Android* Project

Android.mk and Application.mk are located in the subdirectory jni of the Android* application project. Android.mk is a GNU makefile that the build system parses. Android.mk specifies source files and shared libraries to the build system. For a description of the syntax of the Android.mk build file for the C and C++ source files to link to the Android* NDK, go to https://developer.android.com/ndk/guides/android_mk.html. Create the native code makefile Android.mk in the subdirectory jni for all FreeType fonts, which looks like this:

C++
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

FREETYPE_SRC_PATH :=

LOCAL_MODULE := freetype

LOCAL_CFLAGS := -DANDROID_NDK \
  -DFT2_BUILD_LIBRARY=1

LOCAL_C_INCLUDES := $(LOCAL_PATH)/include_all \
  $(FREETYPE_SRC_PATH)include \
  $(FREETYPE_SRC_PATH)src

LOCAL_SRC_FILES := \
 $(FREETYPE_SRC_PATH)src/autofit/autofit.c \
 $(FREETYPE_SRC_PATH)src/base/basepic.c \
 $(FREETYPE_SRC_PATH)src/base/ftapi.c \
 $(FREETYPE_SRC_PATH)src/base/ftbase.c \
 $(FREETYPE_SRC_PATH)src/base/ftbbox.c \
 $(FREETYPE_SRC_PATH)src/base/ftbitmap.c \
 $(FREETYPE_SRC_PATH)src/base/ftdbgmem.c \
 $(FREETYPE_SRC_PATH)src/base/ftdebug.c \
 $(FREETYPE_SRC_PATH)src/base/ftglyph.c \
 $(FREETYPE_SRC_PATH)src/base/ftinit.c \
 $(FREETYPE_SRC_PATH)src/base/ftpic.c \
 $(FREETYPE_SRC_PATH)src/base/ftstroke.c \
 $(FREETYPE_SRC_PATH)src/base/ftsynth.c \
 $(FREETYPE_SRC_PATH)src/base/ftsystem.c \
 $(FREETYPE_SRC_PATH)src/cff/cff.c \
 $(FREETYPE_SRC_PATH)src/pshinter/pshinter.c \
 $(FREETYPE_SRC_PATH)src/pshinter/pshglob.c \
 $(FREETYPE_SRC_PATH)src/pshinter/pshpic.c \
 $(FREETYPE_SRC_PATH)src/pshinter/pshrec.c \
 $(FREETYPE_SRC_PATH)src/psnames/psnames.c \
 $(FREETYPE_SRC_PATH)src/psnames/pspic.c \
 $(FREETYPE_SRC_PATH)src/raster/raster.c \
 $(FREETYPE_SRC_PATH)src/raster/rastpic.c \
 $(FREETYPE_SRC_PATH)src/sfnt/pngshim.c \
 $(FREETYPE_SRC_PATH)src/sfnt/sfntpic.c \
 $(FREETYPE_SRC_PATH)src/sfnt/ttbdf.c \
 $(FREETYPE_SRC_PATH)src/sfnt/ttkern.c \
 $(FREETYPE_SRC_PATH)src/sfnt/ttload.c \
 $(FREETYPE_SRC_PATH)src/sfnt/ttmtx.c \
 $(FREETYPE_SRC_PATH)src/sfnt/ttpost.c \
 $(FREETYPE_SRC_PATH)src/sfnt/ttsbit.c \
 $(FREETYPE_SRC_PATH)src/sfnt/sfobjs.c \
 $(FREETYPE_SRC_PATH)src/sfnt/ttcmap.c \
 $(FREETYPE_SRC_PATH)src/sfnt/sfdriver.c \
 $(FREETYPE_SRC_PATH)src/smooth/smooth.c \
 $(FREETYPE_SRC_PATH)src/smooth/ftspic.c \
 $(FREETYPE_SRC_PATH)src/truetype/truetype.c \
 $(FREETYPE_SRC_PATH)src/type1/t1driver.c \
 $(FREETYPE_SRC_PATH)src/cid/cidgload.c \
 $(FREETYPE_SRC_PATH)src/cid/cidload.c \
 $(FREETYPE_SRC_PATH)src/cid/cidobjs.c \
 $(FREETYPE_SRC_PATH)src/cid/cidparse.c \
 $(FREETYPE_SRC_PATH)src/cid/cidriver.c \
 $(FREETYPE_SRC_PATH)src/pfr/pfr.c \
 $(FREETYPE_SRC_PATH)src/pfr/pfrgload.c \
 $(FREETYPE_SRC_PATH)src/pfr/pfrload.c \
 $(FREETYPE_SRC_PATH)src/pfr/pfrobjs.c \
 $(FREETYPE_SRC_PATH)src/pfr/pfrsbit.c \
 $(FREETYPE_SRC_PATH)src/type42/t42objs.c \
 $(FREETYPE_SRC_PATH)src/type42/t42parse.c \
 $(FREETYPE_SRC_PATH)src/type42/type42.c \
 $(FREETYPE_SRC_PATH)src/winfonts/winfnt.c \
 $(FREETYPE_SRC_PATH)src/pcf/pcfread.c \
 $(FREETYPE_SRC_PATH)src/pcf/pcfutil.c \
 $(FREETYPE_SRC_PATH)src/pcf/pcfdrivr.c \
 $(FREETYPE_SRC_PATH)src/psaux/afmparse.c \
 $(FREETYPE_SRC_PATH)src/psaux/psaux.c \
 $(FREETYPE_SRC_PATH)src/psaux/psconv.c \
 $(FREETYPE_SRC_PATH)src/psaux/psobjs.c \
 $(FREETYPE_SRC_PATH)src/psaux/t1decode.c \
 $(FREETYPE_SRC_PATH)src/tools/apinames.c \
 $(FREETYPE_SRC_PATH)src/type1/t1afm.c \
 $(FREETYPE_SRC_PATH)src/type1/t1gload.c \
 $(FREETYPE_SRC_PATH)src/type1/t1load.c \
 $(FREETYPE_SRC_PATH)src/type1/t1objs.c \
 $(FREETYPE_SRC_PATH)src/type1/t1parse.c\
 $(FREETYPE_SRC_PATH)src/bdf/bdfdrivr.c\
 $(FREETYPE_SRC_PATH)src/bdf/bdflib.c\
 $(FREETYPE_SRC_PATH)src/gzip/ftgzip.c\
 $(FREETYPE_SRC_PATH)src/lzw/ftlzw.c \


LOCAL_LDLIBS := -ldl -llog

include $(BUILD_SHARED_LIBRARY)
Code Sample 1: Android.mk

The NDK build system generates machine code for armeabi by default. To add support to the Intel® architecture, simply add x86 to the APP_ABI variable in jni/Application.mk. You can specify multiple architectures on the same line using space delimited.

C++
APP_ABI := armeabi-v7a x86 #can also be x86_64, armeabi, arm64-v8a, mips, mips64

To generate machine code for all supported instruction sets:

C++
APP_ABI := all #can also be all32 or all64

APP_PLATFORM specifies the name of the target Android* platform. Create the simple native modules build file Application.mk in the subdirectory jni as below:

C++
APP_ABI :=all
APP_PLATFORM := android-20
Code Sample 2: Application.mk

Image 3

Figure 3: Setting APP_ABI in Application.mk

Setting Up Automatic NDK Builds

The first step is to configure the Builders for the project, then select which Builders to enable for the project.

  • Right-click your Android* project, and then choose properties.
  • To add the new builder to the list, select Builders on the left side, and then click the New button.

Image 4

Figure 4: Project properties
  • From the list of configuration types, select Program. The program option allows you to define an external tool location and how to execute the script.

Image 5

Figure 5: Configuration type
  • Name: Type the name of the new builder.
  • Location: Location of the ndk-build.cmd.
  • Working Directory: Browse to the working project.

Image 6

Figure 6: NDK configuration

Building the Project

After the project successfully built, all the libfreetype.so files for all the supported architectures are placed under /lib<APP_ABI>. The <APP_ABI> is x86, x86_64, armeabi, arm64-v8a, armeabi-v7a, mips, or mips64, depending how you set it in APP_ABI in Application.mk.

Image 7

Figure 7: libfreetype.so for x86 devices

Summary

We have described how to set APP_ABI in Application.mk and generate libfreetype.so libraries for x86 devices using an automatic NDK build system.

References

About the Author

Nancy Le is a software engineer at Intel® Corporation in the Software and Services Group working on Intel® Atom™ processor scale-enabling projects.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
Intel is inside more and more Android devices, and we have tools and resources to make your app development faster and easier.


Comments and Discussions

 
-- There are no messages in this forum --