Chapter 2. Java Native Interface

In this chapter, we will cover the following recipes:

  • Loading native libraries and registering native methods
  • Passing parameters and receiving returns in primitive types
  • Manipulating strings in JNI
  • Managing references in JNI
  • Manipulating classes in JNI
  • Manipulating objects in JNI
  • Manipulating arrays in JNI
  • Accessing Java static and instance fields in native code
  • Calling static and instance methods from native code
  • Caching jfieldID, jmethodID, and reference data to improve performance
  • Checking errors and handling exceptions in JNI
  • Integrating assembly code in JNI

Introduction

Programming with Android NDK is essentially writing code in both Java and native languages such as C, C++, and assembly. Java code runs on Dalvik Virtual ...

Get Android Native Development Kit Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.