1

I've taken the working example native-activity and I am trying to add a call inside main() to a function that is available in an already compiled .so file.

I've placed the .so under jniLibs inside its own ABI folder and then added the library name to my gradle build file.

android.ndk {
    moduleName ="native-activity"
    CFlags += "-I${file("src/main/jni/native_app_glue")}".toString()
    ldLibs += ["log", "android", "EGL", "GLESv1_CM", "mylib"]
}

The additional change to ldLibs makes it possible for the code to compile. So it's finding the library. When I am inspecting the apk, it's all in there under the right ABI (armeabi-v7a for Nexus 5 device.)

What's strange is that when I use gradle from the command line, I am getting the following error message:

arch64-linux-android/bin/ld: cannot find -lmylib

Does that mean that it's trying to add a static lmylib.a to the binary?

Of course, by removing "mylib" from the gradle ldLibs list, the app runs again, so it seems that ldLibs is forcing the native-lib to load the .so which fails? But why?

EDIT

The problem is definitely AS unable to link with the so inside jniLibs folder.

Adding:

    ldFlags += "-L${file("src/main/jniLibs/")}".toString()

to the gradle build file doesn't seem to fix the problem. Are flags supported?

John Difool
  • 5,572
  • 5
  • 45
  • 80

1 Answers1

0

Check my question: OpenCv with Android studio 1.3+ using new gradle - undefined reference with this I resolved link error.

android.productFlavors {
    create("armv7") {
            ndk.with {
                abiFilters += "armeabi-v7a"
                File curDir = file('./')
                curDir = file(curDir.absolutePath)
                String libsDir = curDir.absolutePath+"\\src\\main\\jniLibs\\armeabi-v7a\\" //"-L" +
                ldLibs += libsDir + "libnative_camera_r4.3.0.so"
                ldLibs += libsDir + "libopencv_contrib.a"
        }
    }
}
Community
  • 1
  • 1
Petar P
  • 368
  • 4
  • 13