BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News New Tools from Google to Help Developing C/C++ Applications on Android

New Tools from Google to Help Developing C/C++ Applications on Android

Leia em Português

This item in japanese

A new set of libraries and tools from Google's Fun Propulsion Labs, fplutil, promises to make it easier to develop C/C++ applications for Android.

Fplutil is made of four major parts: build_all_android.py, buildutil, libfplutil, and android_ndk_perf.py.

build_all_android.py

This build script allows to build, install, and run native apps from the command line. The script will build C/C++ apps on top of the Android NDK and is useful both for build automation and for streamlining the developer's compile/run loop.

The script supports specifying build settings from the command line, such as to set debug mode, optimization level, etc. It also supports the use of multiple devices at the same time.

buildutil

Buildutil is a set of Python modules that simplify the process of writing continuous automation scripts that use CMake. An example of using buildutil to build/archive an Android app is the following:

  1. First step is creating a android.BuildEnvironment instance to perform the rest of build operations:

    parser = argparse.ArgumentParser()
    buildutil.android.BuildEnvironment.add_arguments(parser)
    args = parser.parse_args()
    env = buildutil.android.BuildEnvironment(args)
    
  2. Once this step is done, the app is built using ndk-build for the native (C/C++) component and ant for the Java component and APK:

    (rc, errmsg) = env.build\_all()
    
  3. Finally, the APK can be archived to a zip file:

    env.make\_archive(['apks'], 'output.zip', exclude=['objs', 'objs-debug'])
    

Besides NDK builds on Android, this tool supports Linux, OS X, and Windows builds.

libfplutil

libfplutil consists of a native Android NDK module that builds two static libraries, libfplutil_main and libfplutil_print, that make it easier to write C/C++ applications:

  • libfplutil_main implements an Android NativeActivity entry point android_main() which calls the traditional C/C++ entry point int main(). This makes it possible to write an application with a int main() entry point (just like any standard C application), link against this library (see Linking) and have it run on Android.

  • libfplutil_print implements a set of wrappers for functions that write to the standard output stream. This enables applications that write to the terminal using printf to have their output redirected to the Android log.

By linking to libfplutil, the canonical Hello, World program can be compiled and run on Android without changes.

android_ndk_perf.py

This is a desktop tool that enables native (C/C++) developers to measure the CPU utilization of their applications on Android, guiding their optimization efforts. Android_ndk_perf can be run on developer's workstations to collect traces of applications running on Android devices. After application traces are collected the data can be examined using Linux Perf's commands or a HTML visualization can be generated for inspection in a web browser.

libfplutil can be downloaded from github, which also hosts its documentation.

Fun Propulsion Labs is a team within Google that's dedicated to advancing gaming on Android and other platforms. Early this year, they open-sourced LiquidFun 1.1, a 2D physics engine including fluid simulation.

Rate this Article

Adoption
Style

BT