Reputation: 295
I have following function in my native-lib.cpp file:
JNIEXPORT jlong JNICALL
Java_com_example_z_myapplication_MainActivity_convert32to64(JNIEnv *env, jobject instance,
jlong l) {
// TODO
l = l + 76561197960265728L;
return l;
}
In my MainActivity.java:
public class MainActivity extends AppCompatActivity {
static {
System.loadLibrary("native-lib");
}
public static native long convert32to64(long l);
...
}
I have a CMakeList.txt:
cmake_minimum_required(VERSION 3.4.1)
# Specifies a library name, specifies whether the library is STATIC or
# SHARED, and provides relative paths to the source code. You can
# define multiple libraries by adding multiple add.library() commands,
# and CMake builds them for you. When you build your app, Gradle
# automatically packages shared libraries with your APK.
add_library( # Specifies the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/cpp/native-lib.cpp )
However I am getting this error:
java.lang.UnsatisfiedLinkError: No implementation found for long com.example.z.myapplication.MainActivity.convert32to64(long) (tried Java_com_example_z_myapplication_MainActivity_convert32to64 and Java_com_example_z_myapplication_MainActivity_convert32to64__J)
can anyone tell me whats wrong here?
Upvotes: 0
Views: 67
Reputation: 3852
You need extern "C"
for C++ JNI.
extern "C" JNIEXPORT jlong JNICALL
Java_com_example_z_myapplication_MainActivity_convert32to64(
JNIEnv *env, jobject instance, jlong l) {
// ...
}
Upvotes: 2