Android Studio不包含apk中的.so库:

时间:2015-03-05 13:04:56

标签: android c++ string android-ndk

我用这种方式调用本机方法:

public native String callTest(String mCurrentPhotoPath);

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

这是我的cpp

#include <jni.h>
#include "opencv2/core/core.hpp"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <stdio.h>

using namespace std;
using namespace cv;

const char* toGray(const char* path){
    IplImage* img = NULL;
    if ((img = cvLoadImage(path))== 0){
        printf("cvLoadImage failed\n");
    }
    return path;
}

extern "C" {

JNIEXPORT jstring JNICALL Java_com_example_MainActivity_callTest(JNIEnv* env, jobject, jstring param) {
    const char* path = env->GetStringUTFChars(param, 0);
    return env->NewStringUTF(toGray(path));
}

}

我已经尝试过toGray在extern之前和之后&#34; C&#34;(当它在我第一次在extern之前宣布之后&#34; C&#34;然后在下面设置它的功能)。 崩溃错误:

03-05 15:12:37.930  13775-13775/com.example E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.UnsatisfiedLinkError: Couldn't load jni_part from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example-1, /vendor/lib, /system/lib]]]: findLibrary returned null
            at java.lang.Runtime.loadLibrary(Runtime.java:359)
            at java.lang.System.loadLibrary(System.java:514)
            at com.example.MainActivity.<clinit>(MainActivity.java:56)
            at java.lang.Class.newInstanceImpl(Native Method)
            at java.lang.Class.newInstance(Class.java:1319)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2223)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
            at android.app.ActivityThread.access$600(ActivityThread.java:156)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:153)
            at android.app.ActivityThread.main(ActivityThread.java:5299)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)

Application.mk

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-15

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

OPENCV_LIB_TYPE:=STATIC
OPENCV_INSTALL_MODULES:=on

include /home/radibg2/OpenCV-2.4.10-android-sdk/sdk/native/jni//OpenCV.mk

LOCAL_MODULE    := jni_part
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_LDLIBS +=  -llog -ldl

include $(BUILD_SHARED_LIBRARY)

1 个答案:

答案 0 :(得分:0)

问题是NDK在libs文件夹中生成库,但它们必须位于jniLibs文件夹中。