1

I have an Android Studio 1.2.2 project setup with some native *.so files included in project -> src -> main -> jniLibs -> armeabi (that's the correct architecture for them). I have a class that loads the library in a static and links to the native methods (I think/hope).

Here is the static with System.loadLibrary:

static {
    try {
        System.loadLibrary("<SOME LIB>");
    } catch(UnsatisfiedLinkError ule){
        Log.e(TAG, "Error while loading library <SOME LIB>", ule);
    }
}

I never hit the catch block or see the error message but I have verified I enter the static and get to the System.loadLibrary line so I don't assume I'm hitting an issue loading it.

I have this imported in another class:

import com.<rest-of-pacakage-name>.<SOME LIB>

and has a native method initialize that takes a byte:

public native static int <SOME LIB>_Initialize(byte[] Parameter);

This was all based off of another eclipse project that I'm porting over the AS.

Any ideas/suggestions or ways I can identify the root cause of why the library load seems to be fine but the method call not?

 07-22 08:38:51.810  27119-27119/com.<rest-of-package-name>.staging E/art﹕ No implementation found for int com.<rest-of-package-name>.pppp_api.PPPP_APIs.PPPP_Initialize(byte[]) (tried Java_com_<rest-of-package-name>_pppp_1api_PPPP_1APIs_PPPP_1Initialize and Java_com_<rest-of-package-name>_pppp_1api_PPPP_1APIs_PPPP_1Initialize___3B)
07-22 08:38:52.360  27119-27119/com.<rest-of-package-name>.staging E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.<rest-of-package-name>.staging, PID: 27119
    java.lang.UnsatisfiedLinkError: No implementation found for int com.<rest-of-package-name>.pppp_api.PPPP_APIs.PPPP_Initialize(byte[]) (tried Java_com_<rest-of-package-name>_pppp_1api_PPPP_1APIs_PPPP_1Initialize and Java_com_<rest-of-package-name>_pppp_1api_PPPP_1APIs_PPPP_1Initialize___3B)
            at com.<rest-of-package-name>.pppp_api.PPPP_APIs.PPPP_Initialize(Native Method)
            at com.<rest-of-package-name>.ui.base.BaseDrawerActivity.setupDrawer(BaseDrawerActivity.java:150)
            at com.<rest-of-package-name>.ui.base.BaseDrawerActivity.onCreate(BaseDrawerActivity.java:99)
            at com.<rest-of-package-name>.ui.main.MainActivity.onCreate(MainActivity.java:15)
            at android.app.Activity.performCreate(Activity.java:6221)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2614)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
            at android.app.ActivityThread.access$900(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5835)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

Package name for class that contains the static and native method:

package com.<rest-of-package-name>.pppp_api;
JoshDM
  • 4,939
  • 7
  • 43
  • 72
isuPatches
  • 6,384
  • 2
  • 22
  • 30
  • You should include the exact error message in your question, as well as the exact declarations of the symbols the message refers to. – Michael Jul 22 '15 at 13:27
  • Thank you...I updated above with the stacktrace – isuPatches Jul 22 '15 at 13:34
  • Could it be that you are missing a "1" in your package name: com.p2p.pppp_1api... instead of com.p2p.pppp_api... ? –  Jul 22 '15 at 13:36
  • I had to update the stacktrace again...I accidentally pulled an old one. I think this has to deal with build flavors...I have a staging flavor that appends .staging...could that be it? – isuPatches Jul 22 '15 at 13:46

1 Answers1

4

1) If you change package name for class that contains native methods, you should change method signature in native code.

2) Try create one more fodler with name armeabi-v7a and copy *.so there because some devices can't use old armeabi and ignore libs in that fodler

3) in module graddle script add this lines inside "android" block:

sourceSets.main {
    jni.srcDirs = []
    jniLibs.srcDir 'src/main/jniLibs'
}
Beyka
  • 1,372
  • 1
  • 10
  • 15
  • You lead me down the right path...thank you. So the issue seems to be that the *.so files had references to a different package name for their native methods. I was only provided the *.so files and the not the C files to change this so I had to create a wrapper module that matched the exact package name and then everything worked. – isuPatches Jul 22 '15 at 17:02