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