1

I received an Eclipse project which I have successfully imported into Android Studio for use. The only problem is that a class in this project calls some function in a .so file that came with the project. I've been unable to call those methods for days now.

The class is pretty basic:

public class Conversions {

  private static Conversions mCom=null;

  public static Conversions getInstance(){
    if(mCom==null){
        mCom=new Conversions();
    }
    return mCom;
  }

  public native int StdToIso(int itype,byte[] input,byte[] output);
  public native int IsoToStd(int itype,byte[] input,byte[] output);
  public native int GetDataType(byte[] input);
  public native int StdChangeCoord(byte[] input,int size,byte[] output,int dk);

  static {
    System.loadLibrary("conversions");
  }
}

The error message is:

cannot resolve corresponding JNI function ....
No JNI_OnLoad found in /data/app-lib/com.example.fpdemo-1/libfgtitinit.so 0x4cc91c70, skipping init

The native methods are in several .so files located in my:

jniLibs > armeabi > libconversions.so
jniLibs > armeabi > libfgtitinit.so

But for some reason, I can't read the native files. I think it might be a build problem or an environment one. My Gradle build files looks something like this:

android {
    compileSdkVersion 17
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "com.example.fpdemo"
        minSdkVersion 12
        targetSdkVersion 17
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
   compile 'com.android.support:support-v4:18.0.0'
   compile files('libs/fgtitdevice.jar')
}
Daniel
  • 2,355
  • 9
  • 23
  • 30
Mueyiwa Moses Ikomi
  • 1,069
  • 2
  • 12
  • 26
  • 1
    check my answer here to include `*.SO libraries` http://stackoverflow.com/a/33164947/3626214 – Aspicas Sep 29 '16 at 11:40
  • 1
    Possible duplicate of [Android NDK: how include \*.so files in AndroidStudio](http://stackoverflow.com/questions/33164778/android-ndk-how-include-so-files-in-androidstudio) – Code-Apprentice Sep 29 '16 at 11:43
  • @Aspicas just tried, didn't work – Mueyiwa Moses Ikomi Sep 29 '16 at 11:48
  • Edit your question and add the C/C++ method definitions you have implemented in libconversions.so – Robert Sep 29 '16 at 14:36
  • i didn't create the files, but be rest assured those function are there. I think gradle or my java class is not reading into it correctly @Robert – Mueyiwa Moses Ikomi Sep 29 '16 at 17:03
  • @Mueyiwa Moses Ikomi: You can not load arbitrary .so files from Java. You have to develop a library that matches your `Conversions` class and it's native methods using Android Native development Kit (NDK). – Robert Sep 29 '16 at 18:17

1 Answers1

1
public class Conversions {

  private static Conversions mCom=null;

  public static Conversions getInstance(){
    if(mCom==null){
        mCom=new Conversions();
    }
    return mCom;
  }

  public native int StdToIso(int itype,byte[] input,byte[] output);
  public native int IsoToStd(int itype,byte[] input,byte[] output);
  public native int GetDataType(byte[] input);
  public native int StdChangeCoord(byte[] input,int size,byte[] output,int dk);

  static {
    System.loadLibrary("conversions");
    System.loadLibrary("libfgtitinit");
  }
}

try to replace this out i hope it will work

Mohit Trivedi
  • 699
  • 3
  • 13