好的,在您将此标记为重复之前,我已尝试以下
No implementation found for native
No implementation found for native Stitch
No Implementation found for native in ndk
No implementation found for native Lcom/jp/algi/
Android NDK C++ JNI (no implementation found for native...)
Android NDK: No implementation found for native xxxxxx
这是我的MainActivity.java
公共类MainActivity扩展了Activity {
static {
System.loadLibrary("physfs");
System.loadLibrary("jpeg");
System.loadLibrary("tiff");
System.loadLibrary("mng");
System.loadLibrary("png");
System.loadLibrary("jasper");
System.loadLibrary("lcms");
System.loadLibrary("devil");
System.loadLibrary("mylib");
}
public static native void convert();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
convert();
}
}
c文件
#include "com_myproject_MainActivity.h"
#include <string.h>
#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
JNIEXPORT void JNICALL Java_com_myproject_MainActivity_convert
(JNIEnv *, jclass){
.....
}
javah生成的标题代码段
#define com_myproject_MainActivity_DEFAULT_KEYS_SHORTCUT 2L
#undef com_myproject_MainActivity_DEFAULT_KEYS_SEARCH_LOCAL
#define com_myproject_MainActivity_DEFAULT_KEYS_SEARCH_LOCAL 3L
#undef com_myproject_MainActivity_DEFAULT_KEYS_SEARCH_GLOBAL
#define com_myproject_MainActivity_DEFAULT_KEYS_SEARCH_GLOBAL 4L
/*
* Class: com_myproject_MainActivity
* Method: convert
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_myproject_MainActivity_convert
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif
源自C文件的android.mk文件部分
#mylib
include $(CLEAR_VARS)
LOCAL_MODULE := libmylib
LOCAL_CFLAGS := -g -Dlinux -DFT2_BUILD_LIBRARY=1 -DPHYSFS_NO_CDROM_SUPPORT=1 -DAL_ALEXT_PROTOTYPES=1 -DHAVE_GCC_DESTRUCTOR=1 -DOPT_GENERIC -DREAL_IS_FLOAT
LOCAL_CPPFLAGS := ${LOCAL_CFLAGS}
LOCAL_C_INCLUDES := \
${DEVIL_SRC_PATH}include \
${DEVIL_SRC_PATH}src-IL/include \
${JASPER_SRC_PATH}src/libjasper/include \
${PNG_SRC_PATH} \
${MNG_SRC_PATH} \
${JPEG_SRC_PATH} \
${LCMS_SRC_PATH}include/ \
${TIFF_SRC_PATH}libtiff/ \
LOCAL_SRC_FILES := com_myproject_MainActivity.c
include $(BUILD_SHARED_LIBRARY)
我已经尝试将C文件作为.cpp并以所有可能的方式使用extern“C”而没有结果。 我还删除了bin,out,libs和obj文件夹几次并且新建了。 代码编译和.so文件。
但我无法运行它这是日志
> 08-02 01:59:07.268: E/Trace(1569): error opening trace file: No such
> file or directory (2) 08-02 01:59:07.268: D/dalvikvm(1569): Trying to
> load lib /data/data/com.myproject/lib/libphysfs.so 0xb63c3518 08-02
> 01:59:07.268: D/dalvikvm(1569): Added shared lib
> /data/data/com.myproject/lib/libphysfs.so 0xb63c3518 08-02
> 01:59:07.268: D/dalvikvm(1569): No JNI_OnLoad found in
> /data/data/com.myproject/lib/libphysfs.so 0xb63c3518, skipping init
> 08-02 01:59:07.268: D/dalvikvm(1569): Trying to load lib
> /data/data/com.myproject/lib/libjpeg.so 0xb63c3518 08-02 01:59:07.268:
> D/dalvikvm(1569): Added shared lib
> /data/data/com.myproject/lib/libjpeg.so 0xb63c3518 08-02 01:59:07.268:
> D/dalvikvm(1569): No JNI_OnLoad found in
> /data/data/com.myproject/lib/libjpeg.so 0xb63c3518, skipping init
> 08-02 01:59:07.268: D/dalvikvm(1569): Trying to load lib
> /data/data/com.myproject/lib/libtiff.so 0xb63c3518 08-02 01:59:07.268:
> D/dalvikvm(1569): Added shared lib
> /data/data/com.myproject/lib/libtiff.so 0xb63c3518 08-02 01:59:07.268:
> D/dalvikvm(1569): No JNI_OnLoad found in
> /data/data/com.myproject/lib/libtiff.so 0xb63c3518, skipping init
> 08-02 01:59:07.268: D/dalvikvm(1569): Trying to load lib
> /data/data/com.myproject/lib/libmng.so 0xb63c3518 08-02 01:59:07.268:
> D/dalvikvm(1569): Added shared lib
> /data/data/com.myproject/lib/libmng.so 0xb63c3518 08-02 01:59:07.268:
> D/dalvikvm(1569): No JNI_OnLoad found in
> /data/data/com.myproject/lib/libmng.so 0xb63c3518, skipping init 08-02
> 01:59:07.268: D/dalvikvm(1569): Trying to load lib
> /data/data/com.myproject/lib/libpng.so 0xb63c3518 08-02 01:59:07.268:
> D/dalvikvm(1569): Added shared lib
> /data/data/com.myproject/lib/libpng.so 0xb63c3518 08-02 01:59:07.268:
> D/dalvikvm(1569): No JNI_OnLoad found in
> /data/data/com.myproject/lib/libpng.so 0xb63c3518, skipping init 08-02
> 01:59:07.268: D/dalvikvm(1569): Trying to load lib
> /data/data/com.myproject/lib/libjasper.so 0xb63c3518 08-02
> 01:59:07.268: D/dalvikvm(1569): Added shared lib
> /data/data/com.myproject/lib/libjasper.so 0xb63c3518 08-02
> 01:59:07.268: D/dalvikvm(1569): No JNI_OnLoad found in
> /data/data/com.myproject/lib/libjasper.so 0xb63c3518, skipping init
> 08-02 01:59:07.268: D/dalvikvm(1569): Trying to load lib
> /data/data/com.myproject/lib/liblcms.so 0xb63c3518 08-02 01:59:07.268:
> D/dalvikvm(1569): Added shared lib
> /data/data/com.myproject/lib/liblcms.so 0xb63c3518 08-02 01:59:07.268:
> D/dalvikvm(1569): No JNI_OnLoad found in
> /data/data/com.myproject/lib/liblcms.so 0xb63c3518, skipping init
> 08-02 01:59:07.268: D/dalvikvm(1569): Trying to load lib
> /data/data/com.myproject/lib/libdevil.so 0xb63c3518 08-02
> 01:59:07.268: D/dalvikvm(1569): Added shared lib
> /data/data/com.myproject/lib/libdevil.so 0xb63c3518 08-02
> 01:59:07.268: D/dalvikvm(1569): No JNI_OnLoad found in
> /data/data/com.myproject/lib/libdevil.so 0xb63c3518, skipping init
> 08-02 01:59:07.268: D/dalvikvm(1569): Trying to load lib
> /data/data/com.myproject/lib/libmylib.so 0xb63c3518 08-02
> 01:59:07.268: D/dalvikvm(1569): Added shared lib
> /data/data/com.myproject/lib/libmylib.so 0xb63c3518 08-02
> 01:59:07.268: D/dalvikvm(1569): No JNI_OnLoad found in
> /data/data/com.myproject/lib/libmylib.so 0xb63c3518, skipping init
> 08-02 01:59:07.288: W/dalvikvm(1569): No implementation found for
> native Lcom/myproject/MainActivity;.convert:()V 08-02 01:59:07.288:
> D/AndroidRuntime(1569): Shutting down VM 08-02 01:59:07.288:
> W/dalvikvm(1569): threadid=1: thread exiting with uncaught exception
> (group=0xb5e5e288) 08-02 01:59:07.288: E/AndroidRuntime(1569): FATAL
> EXCEPTION: main 08-02 01:59:07.288: E/AndroidRuntime(1569):
> java.lang.UnsatisfiedLinkError: Native method not found:
> com.myproject.MainActivity.convert:()V 08-02 01:59:07.288:
> E/AndroidRuntime(1569): at com.myproject.MainActivity.convert(Native
> Method) 08-02 01:59:07.288: E/AndroidRuntime(1569): at
> com.myproject.MainActivity.onCreate(MainActivity.java:30) 08-02
> 01:59:07.288: E/AndroidRuntime(1569): at
> android.app.Activity.performCreate(Activity.java:5008) 08-02
> 01:59:07.288: E/AndroidRuntime(1569): at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
> 08-02 01:59:07.288: E/AndroidRuntime(1569): at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
> 08-02 01:59:07.288: E/AndroidRuntime(1569): at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
> 08-02 01:59:07.288: E/AndroidRuntime(1569): at
> android.app.ActivityThread.access$600(ActivityThread.java:130) 08-02
> 01:59:07.288: E/AndroidRuntime(1569): at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
> 08-02 01:59:07.288: E/AndroidRuntime(1569): at
> android.os.Handler.dispatchMessage(Handler.java:99) 08-02
> 01:59:07.288: E/AndroidRuntime(1569): at
> android.os.Looper.loop(Looper.java:137) 08-02 01:59:07.288:
> E/AndroidRuntime(1569): at
> android.app.ActivityThread.main(ActivityThread.java:4745) 08-02
> 01:59:07.288: E/AndroidRuntime(1569): at
> java.lang.reflect.Method.invokeNative(Native Method) 08-02
> 01:59:07.288: E/AndroidRuntime(1569): at
> java.lang.reflect.Method.invoke(Method.java:511) 08-02 01:59:07.288:
> E/AndroidRuntime(1569): at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
> 08-02 01:59:07.288: E/AndroidRuntime(1569): at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 08-02
> 01:59:07.288: E/AndroidRuntime(1569): at
> dalvik.system.NativeStart.main(Native Method)
由于某种原因,该方法没有被看到,但是库正在加载.... 为了它的价值,我从here编辑了这段代码并取出了我需要的东西。 感谢名单
答案 0 :(得分:1)
在源文件中:
Java_com_myproject_ndk_convert
但是javah有:
Java_com_myproject_MainActivity_convert
日志还说:
No implementation found for native Lcom/myproject/MainActivity;.convert:
你的意思是写:
Java_com_myproject_MainActivity_convert