Create your first JNI Application on Android with the NDK

classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle-experimental:0.7.2'
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
apply plugin: 'com.android.model.application'model {
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.ssaurel.hellojni"
minSdkVersion.apiLevel 22
targetSdkVersion.apiLevel 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles.add(file('proguard-android.txt'))
}
}
}
}
ndk {
moduleName "hello-jni"
}
// end of the class … static {
System.loadLibrary("hello-jni");
}
public native String getMsgFromJni();} // class MainActivity
#include <jni.h>JNIEXPORT jstring JNICALL
Java_com_google_sample_helloandroidjni_MainActivity_getMsgFromJni(JNIEnv *env, jobject instance) {
// Put your code here return (*env)->NewStringUTF(env, "Hello From JNI");
}
((TextView) findViewById(R.id.msgView)).setText(getMsgFromJni());

--

--

Entrepreneur / Developer / Blogger / Author. In Bitcoin We Trust: https://inbitcoinwetrust.substack.com/

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sylvain Saurel

Sylvain Saurel

Entrepreneur / Developer / Blogger / Author. In Bitcoin We Trust: https://inbitcoinwetrust.substack.com/