Game Development Reference
In-Depth Information
How to do it...
Carry out the following steps to create a placeholder for our C++ code:
1.
Add the jni/Wrappers.cpp ile with the following code:
#include <stdlib.h>
#include <jni.h>
#include <android/log.h>
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO,
"App2", __VA_ARGS__))
extern "C"
{
JNIEXPORT void JNICALL
Java_com_packtpub_ndkcookbook_app2_App2Activity_onCreateNative(
JNIEnv* env, jobject obj )
{
LOGI( "Hello World!" );
}
}
2.
We need to change our Activity class from the previous recipe to make use of the
native code we just added in the preceding section, through the following code:
package com.packtpub.ndkcookbook.app2;
import android.app.Activity;
import android.os.Bundle;
public class App2Activity extends Activity
{
static
{
Here we load the native library named libApp2.so . Note the omitted lib preix and
.so extension:
System.loadLibrary( "App2" );
}
@Override protected void onCreate( Bundle icicle )
{
super.onCreate( icicle );
onCreateNative();
}
public static native void onCreateNative();
};
 
Search WWH ::




Custom Search