如何使用JNI,NDK导入开源库

时间:2018-06-29 06:31:08

标签: android android-ndk ini

我想在我的项目中使用该库进行编辑。因此,我安装了NDK并设置了NDK-bundle路径。但是这个错误出现在我的日志中。

6-29 15:14:42.174 15069-15069/com.softcode.kihnoplay E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.softcode.kihnoplay, PID: 15069
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.softcode.kihnoplay-1/base.apk", zip file "/data/app/com.softcode.kihnoplay-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.softcode.kihnoplay-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.softcode.kihnoplay-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.softcode.kihnoplay-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.softcode.kihnoplay-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.softcode.kihnoplay-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.softcode.kihnoplay-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.softcode.kihnoplay-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.softcode.kihnoplay-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.softcode.kihnoplay-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.softcode.kihnoplay-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.softcode.kihnoplay-1/lib/arm, /data/app/com.softcode.kihnoplay-1/base.apk!/lib/armeabi-v7a, /data/app/com.softcode.kihnoplay-1/split_lib_dependencies_apk.apk!/lib/armeabi-v7a, /data/app/com.softcode.kihnoplay-1/split_lib_slice_0_apk.apk!/lib/armeabi-v7a, /data/app/com.softcode.kihnoplay-1/split_lib_slice_1_apk.apk!/lib/armeabi-v7a, /data/app/com.softcode.kihnoplay-1/split_lib_slice_2_apk.apk!/lib/armeabi-v7a, /data/app/com.softcode.kihnoplay-1/split_lib_slice_3_apk.apk!/lib/armeabi-v7a, /data/app/com.softcode.kihnoplay-1/split_lib_slice_4_apk.apk!/lib/armeabi-v7a, /data/app/com.softcode.kihnoplay-1/split_lib_slice_5_apk.apk!/lib/armeabi-v7a, /data/app/com.softcode.kihnoplay-1/split_lib_slice_6_apk.apk!/lib/armeabi-v7a, /data/app/com.softcode.kihnoplay-1/split_lib_slice_7_apk.apk!/lib/armeabi-v7a, /data/app/com.softcode.kihnoplay-1/split_lib_slice_8_apk.apk!/lib/armeabi-v7a, /data/app/com.softcode.kihnoplay-1/split_lib_slice_9_apk.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]] couldn't find "libARM_ARCH.so"
    at java.lang.Runtime.loadLibrary0(Runtime.java:972)
    at java.lang.System.loadLibrary(System.java:1567)
    at FFmpegAndroid.src.main.java.com.github.hiteshsondhi88.libffmpeg.ArmArchHelper.<clinit>(ArmArchHelper.java:5)
    at FFmpegAndroid.src.main.java.com.github.hiteshsondhi88.libffmpeg.CpuArchHelper.getCpuArch(CpuArchHelper.java:16)
    at FFmpegAndroid.src.main.java.com.github.hiteshsondhi88.libffmpeg.FFmpeg.loadBinary(FFmpeg.java:38)
    at com.softcode.tablet.Mp3Concat_Thread.startThread(Mp3Concat_Thread.java:93)
    at com.softcode.tablet.Mp3Concat_Thread.<init>(Mp3Concat_Thread.java:53)
    at com.softcode.phone.record.view.RecordActivity.onCreate(RecordActivity.java:183)
    at android.app.Activity.performCreate(Activity.java:6955)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
    at android.app.ActivityThread.-wrap14(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6776)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

这是开源库中的ArmArchHelper.class。

package FFmpegAndroid.src.main.java.com.github.hiteshsondhi88.libffmpeg;

class ArmArchHelper {
static {
    System.loadLibrary("ARM_ARCH");
}

native String cpuArchFromJNI();

boolean isARM_v7_CPU(String cpuInfoString) {
    return cpuInfoString.contains("v7");
}

boolean isNeonSupported(String cpuInfoString) {
    // check cpu arch for loading correct ffmpeg lib
    return cpuInfoString.contains("-neon");
}

}

这是ini文件夹中库中的armArch.c。

#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
#include <cpu-features.h>

 JNIEXPORT jstring JNICALL
  Java_com_github_hiteshsondhi88_libffmpeg_ArmArchHelper_cpuArchFromJNI(JNIEnv* env, jobject obj)
{
char arch_info[11] = "";

// checking if CPU is of ARM family or not
if (android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM) {
    strcpy(arch_info, "ARM");

    // checking if CPU is ARM v7 or not
    uint64_t cpuFeatures = android_getCpuFeatures();
    if ((cpuFeatures & ANDROID_CPU_ARM_FEATURE_ARMv7) != 0) {
        strcat(arch_info, " v7");

        // checking if CPU is ARM v7 Neon
        if((cpuFeatures & ANDROID_CPU_ARM_FEATURE_NEON) != 0) {
            strcat(arch_info, "-neon");
        }
    }
}
return (*env)->NewStringUTF(env, arch_info);
}

如果您现在如何解决此问题,请告诉我。谢谢。

1 个答案:

答案 0 :(得分:0)

您是否将armArch.c文件编译到libARM_ARCH.so中? 其他 如果要编译为说libsomething.so,则将命令更改为System.loadLibrary(“ something”)