1

I got a .so file from Android aar package with x86 , x86_64, armv7 etc.

Would it be possible for me to call the function in the .so file?

What I have been tried

enter image description here

created a main.c

#include <stdio.h>
int main() {
        printf("Hello World!\n");
        printf("%d", Java_com_scaf_android_client_CodecUtils_stringFromJNI());
        return 0;
}

execute $ gcc -o main -lLockCore main.c

and I faced this error

main.c:4:15: warning: implicit declaration of function ‘Java_com_scaf_android_client_CodecUtils_stringFromJNI’ [-Wimplicit-function-declaration]
  printf("%d", Java_com_scaf_android_client_CodecUtils_stringFromJNI());
               ^
/tmp/cc9vP9rb.o: In function `main':
main.c:(.text+0x14): undefined reference to `Java_com_scaf_android_client_CodecUtils_stringFromJNI'
collect2: error: ld returned 1 exit status
benleung
  • 871
  • 4
  • 12
  • 25
  • You're not calling the method with the right arguments so even if it did link, it wouldn't work. JNI methods require a JVM context at the very least. If you know what the Java declaration of this method is, you can map it to the JNI version. Take a look at this question for how to instantiate the JVM to make JNI calls: https://stackoverflow.com/questions/37068624/how-to-call-jni-function-from-a-method-in-c-library – TainToTain Aug 04 '20 at 19:27

0 Answers0