The manufacturer gave me an audio codec binary ‘libasc_decoder.so’. From what I’ve read, binary can just be included in ‘main/jniLibs’, and it’ll be automatically compiled with the project. Then I just have to call System.loadLibrary("asc_decoder")
. I built apk and analyzed apk, and I see the binary file in lib folder. However, when I call the native method init()
, I get error ‘implementation not found’.
I also see suggestions to just name it ‘libs’ instead of ‘jniLibs’, and add sourceSet in ‘app/build.gradle’
sourceSets {
main {
jniLibs.srcDirs = ['./src/main/libs']
jni.srcDirs = []
}
}
In both cases, when I run ‘Analyze APK…’ in android studio. I can see the binary was successfully compiled. but when below code doesn’t load any binary method at all
public class ASCDecoder {
static {
System.loadLibrary("asc_decoder");
}
public final static int ASC_I = 1;
public final static int ASC_II = 2;
public final static int ASC_III = 3;
public final static int ASC_IV = 4;
public final static int ASC_V = 5;
public final static int ASC_VI = 6;
public final static int ASC_VII = 7;
public native short init(short codec);
public native int readHead(short[] bytes);
public native short[] decode(short[] bytes, short len, short codec);
public native static void destroy();
}