0
我正在尝试使用Android JNI。 到目前为止,我刚刚编写了基本的Hello World Android JNI应用程序。 现在我正在考虑是否可以单独构建一个.so文件。然后在我的JNI Layer C代码中使用该库。Android JNI在C代码中使用Pre built .so文件
所以基本上我想在Windows中使用命令行gcc构建一个libsample.so。然后在我为Android应用程序编写的JNI中使用这个.so文件。 到目前为止,从我的理解,我应该能够通过编辑Android.mk文件来做到这一点。
但这些编辑会是什么?
编辑:附加的源代码。
jnitest.cpp -
#include <jni.h>
#include "specialPrint.h"
extern "C" jstring Java_com_example_hwjni_MainActivity_helloFromJni(JNIEnv *env, jobject thiz) {
return env->NewStringUTF(SpecialPrint("This is external .so talking."));
}
specialPrint.h -
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
char* SpecialPrint(char* s);
#ifdef __cplusplus
}
#endif
specialPrint.c -
#include <stdio.h>
#include "specialPrint.h"
char* SpecialPrint(char* s) {
return s;
}
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := MyPrebuiltLib
LOCAL_SRC_FILES = specialPrint.c
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := jnitest
LOCAL_SRC_FILES := jnitest.cpp
LOCAL_SHARED_LIBRARIES := MyPrebuiltLib
include $(BUILD_SHARED_LIBRARY)
P.S. - 虽然现在我正在尝试与来源做到这一点。但最终我真的需要做这些东西,没有specialPrint的来源。如果你能帮助我实现这一点,那就太棒了!
由于为答复。但我得到这个错误:D:/android-ndk-r9d-windows-x86_64/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/arm-linux-androideabi-trip :./ libs/armeabi/speciallib.so:无法识别的文件格式 – yashdosi
您确定speciallib.so是用于arm arch吗? – nizammoidu
没有其他的..我肯定要么..我用gcc创建这样的文件使用gcc -shared命令。我需要传递更多的参数来获得.so文件的手臂拱吗? – yashdosi