Last active
February 16, 2019 13:24
-
-
Save this-kirke/f57f36e44bde36d0303cddd150437902 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.test; | |
public class TestClass { | |
private native String stringFromJNI(); | |
public String getString(){ | |
return stringFromJNI(); | |
} | |
public TestClass(){ | |
// Replace with your assembly name | |
System.loadLibrary( "test_assembly" ); | |
} | |
public static void main(String[] args) { | |
TestClass test = new TestClass(); | |
System.out.println( test.getString() ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestClass{ | |
public: | |
static constexpr const char* Name(){ return "com/test/TestClass"; }; | |
static jni::Local<jni::String> TestMethod( jni::JNIEnv& environment, jni::Class<TestClass>& ){ | |
return jni::Make<jni::String>( environment, "Hello from JNI !" ); | |
} | |
}; | |
JNIEXPORT jni::jint JNICALL JNI_OnLoad( jni::JavaVM* vm, void* ){ | |
jni::JNIEnv& environment { jni::GetEnv( *vm ) }; | |
jni::RegisterNatives( | |
environment, | |
*jni::Class<TestClass>::Find( environment ), | |
jni::MakeNativeMethod<decltype(&TestClass::TestMethod), &TestClass::TestMethod>( "stringFromJNI" ) | |
); | |
return jni::Unwrap( jni::jni_version_1_6 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment