Search code examples
androidandroid-ndkjava-native-interface

android cannot find corresponding jni function


I've followed here and I've added the .so files to my android project. Loaded the library and the project runs.

Now I want to use a function of the library. I tried like this in my MainActivity:

public final static native int crypto_aead_chacha20poly1305_encrypt(byte[] jarg1, int[] jarg2, byte[] jarg3, int jarg4, byte[] jarg5, int jarg6, byte[] jarg7, byte[] jarg8, byte[] jarg9);

Android gives me that he cannot find the corresponding JNI function.

The so files are in jniLibs in the right architecture map.

Has this something to do with my packagename that he tries to find it in my package instead of in the so library?

When I run this I get:

java.lang.UnsatisfiedLinkError: No implementation found for int be.example.libtest.MainActivity.crypto_aead_chacha20poly1305_encrypt(byte[], int[], byte[], int, byte[], int, byte[], byte[], byte[]) (tried Java_be_example_libtest_MainActivity_crypto_1aead_1chacha20poly1305_1encrypt and Java_be_example_libtest_MainActivity_crypto_1aead_1chacha20poly1305_1encrypt___3B_3I_3BI_3BI_3B_3B_3B)

Solution

  • I see that Robosodium uses Swig to generate wrapper. In this case there should be also some automatically generated Java files in src/main/java/org/abstractj/kalium that need to be added to your project as well. All native calls should be made using methods provided in that classes.