Book Image

Android NDK Beginner's Guide

By : Sylvain Ratabouil
Book Image

Android NDK Beginner's Guide

By: Sylvain Ratabouil

Overview of this book

<p>Android NDK is all about injecting high performance into your apps. Exploit the maximum power of these mobile devices using high-performance and portable code.</p> <p>This book will show you how to create C/C++ enabled applications and integrate them with Java. You will learn how to access native API and port libraries used in some of the most successful Android applications.</p> <p>Using this practical step-by-step tutorial, highlighted with comments and tricks, discover how to run C/C++ code embedded in a Java application or in a standalone application. You will create a real native application starting from project creation through to full implementation of native API and the porting of existing third-party libraries. You will discover OpenGL ES and OpenSL ES, which are becoming the new standard in mobility. You will also understand how to access keyboard and input peripherals and how to read accelerometer or orientation sensors.</p> <p>Finally, you will dive into more advanced topics such as debugging and troubleshooting applications. By the end of the book, you should know the key elements to enable you to start exploiting the power and portability of native code.</p>
Table of Contents (19 chapters)
Android NDK Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – building a native key/value store


Let’s take care of the Java side first:

  1. Create a new hybrid Java/C++ project like shown in the previous chapter:

    • Name it Store.

    • Its main package is com.packtpub.

    • Its main activity is StoreActivity.

    • Do not forget to create a jni directory at project’s root.

    Let’s work on the Java side first, which is going to contain three source files: Store.java, StoreType.java, and StoreActivity.java.

  2. Create a new class Store which loads the eponym native library and defines the functionalities our key/value store provides. Store is a front-end to our native code. To get started, it supports only integers and strings:

    public class Store {
        static {
            System.loadLibrary("store");
        }
    
        public native int getInteger(String pKey);
        public native void setInteger(String pKey, int pInt);
    
        public native String getString(String pKey);
        public native void setString(String pKey, String pString);
    }
  3. Create StoreType.java with an enumeration specifying...