Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add an existing .so library to an Android Studio project?

There are several sources out there that say you should create a directory in src/main/ called jniLibs/armeabi and add your compiled .so file to this location. Then load your library using System.loadLibrary("nameOflib").

My issue is that when I define my function

public native long create();

create() gives the error:

Cannot resolve corresponding JNI function Java_com_brendan_myApplication_MainActivity_create. Reports native method declarations in Java where no corresponding JNI function is found in the project.

Any ideas?

like image 554
Brendan Cordingley Avatar asked Dec 12 '25 13:12

Brendan Cordingley


2 Answers

Turns out I can still call the jni methods even though there is an error saying "Cannot resolve corresponding JNI function".

like image 182
Brendan Cordingley Avatar answered Dec 15 '25 05:12

Brendan Cordingley


to solve that problem, just follow this steps and visit a link below:

Adding .so Library in Android Studio 1.0.2

  1. Create Folder "jniLibs" inside "src/main/"
  2. Put all your .so libraries inside "src/main/jniLibs" folder
  3. Folder structure looks like,
    |--app:
    |--|--src:
    |--|--|--main
    |--|--|--|--jniLibs
    |--|--|--|--|--armeabi
    |--|--|--|--|--|--.so Files
  4. No extra code requires just sync your project and run your application.

    Reference
    https://github.com/commonsguy/sqlcipher-gradle/tree/master/src/main

From: How to include *.so library in Android Studio?

EDIT: I suppose that might not be problem with configuration, but with how you declare native method signatures in Android NDK

Check this link: What is the correct way to write native method signatures in Android NDK?

Hope it help


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!