JNIExport
The JNIExport aspect, available when writing native Android NDK extensions using the Island platform, allows you to easily mark your public methods to be exported in a way that they can be called from the Java based portions of your app, via JNI.
Essentially, the aspect just applies the simpler SymbolName aspect, using the proper naming conventions required by JNI to match the method up. It also applies the DllExport and Used aspects to make sure the function is exported, and does not get eliminated by the linker.
Parameters
The JNIExport aspect requires as parameter the name of the Java-level class that this native method should be mapped into. Optionally, a MethodName can also be provided, if the method should be exposed to JNI under a different name than used locally.
[JNIExport(ClassName := 'org.me.androidapp.MainActivity')]
method HelloFromNDK(env: ^JNIEnv; this: jobject): jstring;
begin
result := env^^.NewStringUTF(env, 'Hello from NDK');
end;
[JNIExport(ClassName = "org.me.androidapp.MainActivity")]
public jsstring HelloFromNDK(JNIEnv *env, jobject thiz)
{
return (*env)->NewStringUTF(env, "Hello from NDK");
}
@JNIExport(ClassName = "org.me.androidapp.MainActivity")
public func HelloFromNDK(env: UnsafePointer<JNIEnv>!, this: jobject!) -> jstring! {
return (*(*env)).NewStringUTF(env, "Hello from NDK")
}
@JNIExport(ClassName = "org.me.androidapp.MainActivity")
public jsstring HelloFromNDK(JNIEnv *env, jobject thiz)
{
return (*(*env)).NewStringUTF(env, "Hello from NDK");
}
Background
JNI uses specific rules for that, namely the export name must start with "Java_", followed by the full name of the Java-level class (with the dots replaced by underscores), and finally the method name itself. The JNIExport aspect handles this name mangling for you, so the full export name of the example above would be: "Java_org_me_androidapp_MainActivity_HelloFromNDK".
Island/Android Only
The JNIExport aspect is available on the Island platform.
Defined in RemObjects.Elements.Cirrus.dll
See Also
- Java Native Interface (JNI)
- Mixing Android NDK and SDK
SymbolName,DllExportandUsedAspectsExternalAspect for Mercury- Android NDK Platform
- Creating an Android NDK Extension Tutorial