3

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?

Brendan Cordingley
  • 190
  • 1
  • 4
  • 20
  • Which version of Android Studio and which gradle plugin are you using? – Alex Cohn Dec 30 '15 at 06:01
  • Android Studio 1.5.1, gradle 2.8 – Brendan Cordingley Dec 30 '15 at 16:09
  • Is this [tag:gradle-experimental]? – Alex Cohn Dec 30 '15 at 17:17
  • not sure, it is one of the latest versions. I could try an older version to see if there is a difference. – Brendan Cordingley Dec 30 '15 at 18:14
  • Yes, there is a major difference in **build.gradle** file syntax. If you have `apply plugin: 'com.android.application'` then the [instructions](http://stackoverflow.com/a/34521313/192373) by [piotrek1543](http://stackoverflow.com/users/4730812/piotrek1543) are just what you need. But don't expect Android Studio to resolve magically the native method declarations into a prebuilt library. – Alex Cohn Dec 30 '15 at 20:22

2 Answers2

3

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

Brendan Cordingley
  • 190
  • 1
  • 4
  • 20
1

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

Community
  • 1
  • 1
piotrek1543
  • 19,130
  • 7
  • 81
  • 94
  • This is what I am doing, and I am getting the error I described above. – Brendan Cordingley Dec 30 '15 at 16:08
  • please look into link below "How to include..." there are some more answers – piotrek1543 Dec 30 '15 at 16:15
  • I have attempted these solutions with no luck. – Brendan Cordingley Dec 30 '15 at 17:02
  • 1
    I feel as though you are correct. I believe my libraries are loading correctly. I have worked with jni using Eclipse without issues so i wonder why my declarations are being stubborn. – Brendan Cordingley Dec 30 '15 at 17:18
  • i have .so file of other app that i have decompile i don't have native-lib.cpp file of that .so means i don't have native code i only have .so can i integrate and run it in my project because when i m runing the project this error is coming java.lang.UnsatisfiedLinkError: No implementation found for int com.krunal.camarademo.Libs.nativesystem.DMDHDR.getBracketedCount() (tried Java_com_krunal_camarademo_Libs_nativesystem_DMDHDR_getBracketedCount and Java_com_krunal_camarademo_Libs_nativesystem_DMDHDR_getBracketedCount__) – karan Jan 09 '23 at 11:14