java.lang.UnsatisfiedLinkError:无法从loader dalvik.system.PathClassLoader加载cpuinfo

时间:2015-03-06 06:02:27

标签: java android nativelibrary

我正在开发一个需要CPU信息的应用程序。我将cpuinfo库放在jni文件夹中。但我得到了这个错误:

  

java.lang.UnsatisfiedLinkError:无法从loader加载cpuinfo   dalvik.system.PathClassLoader [dexPath = /数据/应用/ com.iman.marashi.deviceinfo-2.apk,libraryPath = /数据/ APP-LIB / com.iman.marashi.deviceinfo-2]:   findLibrary返回null

从这段代码中得到错误:

static {
    try {
        System.loadLibrary("cpuinfo");
        isAvailable = true;
    } catch (UnsatisfiedLinkError ule) {
        Log.e("Loading cpuinfo native library", "" + ule);
    }

cpuinfo.c 代码:

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

 #define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, "jason", __VA_ARGS__)
 #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,   "jason", __VA_ARGS__)
 #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,    "jason", __VA_ARGS__)
 #define LOGW(...) __android_log_print(ANDROID_LOG_WARN,    "jason", __VA_ARGS__)
 #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,   "jason", __VA_ARGS__)

 const int cpu_features_list[] = {
     ANDROID_CPU_ARM_FEATURE_ARMv7,
     ANDROID_CPU_ARM_FEATURE_VFPv3,
     ANDROID_CPU_ARM_FEATURE_NEON,
     ANDROID_CPU_ARM_FEATURE_LDREX_STREX,
     ANDROID_CPU_ARM_FEATURE_VFPv2,
     ANDROID_CPU_ARM_FEATURE_VFP_D32,
     ANDROID_CPU_ARM_FEATURE_VFP_FP16,
     ANDROID_CPU_ARM_FEATURE_VFP_FMA,
     ANDROID_CPU_ARM_FEATURE_NEON_FMA,
     ANDROID_CPU_ARM_FEATURE_IDIV_ARM,
     ANDROID_CPU_ARM_FEATURE_IDIV_THUMB2,
     ANDROID_CPU_ARM_FEATURE_iWMMXt,
     ANDROID_CPU_X86_FEATURE_SSSE3,
     ANDROID_CPU_X86_FEATURE_POPCNT,
     ANDROID_CPU_X86_FEATURE_MOVBE
 };

 const char cpu_features_string_list[][20] = {
     "armv7",
     "vfpv3",
     "neon",
     "ldrex_strex",
     "vfpv2",
     "vfp_d32",
     "vfp_fp16",
     "vfp_fma",
     "neon_fma",
     "idiv_arm",
     "idiv_thumb2",
     "iwmmxt",
     "ssse3",
     "popcnt",
     "movbe"
 };

 void appendString(char *strDestination, char *strSource) {
     strcat(strDestination, " ");
     strcat(strDestination, strSource);
 }

 char* get_cpu_family() {
     if (android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM) {
         return "ARM";
     } else if (android_getCpuFamily() == ANDROID_CPU_FAMILY_X86) {
         return "X86";
     } else if (android_getCpuFamily() == ANDROID_CPU_FAMILY_MIPS) {
         return "MIPS";
     } else {
         return "Unknown";
     }
 }

 char* get_cpu_features() {
     char cpu_features[256] = "";
     uint64_t features = android_getCpuFeatures();

     int i = 0;
     int features_length = sizeof(cpu_features_list) / sizeof(int);
     for (i = 0; i < features_length; i++) {
         if (features & cpu_features_list[i]) {
             appendString(cpu_features, cpu_features_string_list[i]);
         }
     }

     return cpu_features;
 }

 jstring
 Java_hardwareinfo_HardwareInfoActivity_getCpuFamilyFromJNI( JNIEnv* env,
                                                jobject thiz )
 {
     return (*env)->NewStringUTF(env, get_cpu_family());
 }

 jstring
 Java_hardwareinfo_HardwareInfoActivity_getCpuCountFromJNI( JNIEnv* env,
                                                jobject thiz )
 {
     return android_getCpuCount();
 }

 jstring
 Java_hardwareinfo_HardwareInfoActivity_getCpuFeaturesFromJNI( JNIEnv* env,
                                                jobject thiz )
 {
     char buffer[256];
     strlcpy(buffer, get_cpu_features(), sizeof buffer);
     return (*env)->NewStringUTF(env, buffer);
 }

Application.mk 代码:

# Build both ARMv5TE and ARMv7-A machine code.
APP_ABI := armeabi armeabi-v7a

Android.mk 代码:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := cpuinfo
LOCAL_SRC_FILES := cpuinfo.c
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
LOCAL_CFLAGS := -DHAVE_NEON=1
#LOCAL_SRC_FILES += cpuinfo-intrinsics.c.neon
endif
LOCAL_STATIC_LIBRARIES := cpufeatures
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
$(call import-module,cpufeatures)

0 个答案:

没有答案