0
我正在測試Android應用程序中的集成靜態庫。 不幸的是編譯不起作用!你能幫我嗎?使用靜態庫的Android NDK - >函數尚未聲明
我總是得到錯誤:
jni/main-jni.cpp: In function 'jint Java_com_tmz_cc_MainActivity_test1(JNIEnv*, jobject)': jni/main-jni.cpp:10:23: error: 'FileSync' has not been declared
make: *** [obj/local/armeabi/objs/ccSharedLib/main-jni.o] Error 1
我想通過鏈接將是 「FileSync」 之稱。
考慮以下幾點:
project
+- ..
+-jni
+- include
+- prebuild
+- libFileSync.a
+- Android.mk
+- main-jni.cpp
Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := fileSyncStaticLibrary
LOCAL_SRC_FILES := prebuild/libFileSync.a
LOCAL_EXPORT_C_INCLUDES := include/
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := ccSharedLib
LOCAL_SRC_FILES := main-jni.cpp
LOCAL_STATIC_LIBRARIES := fileSyncStaticLibrary
include $(BUILD_SHARED_LIBRARY)
主jni.cpp
#include <jni.h>
#include <stdio.h>
extern "C" {
jint Java_com_tmz_cc_MainActivity_test1(JNIEnv* env, jobject thiz) {
//FileSync *file = new FileSync("connection");
jstring seperator = FileSync::getPathSeperator();
jint temp = 0;
return temp;
}
jint Java_com_tmz_cc_MainActivity_test2(JNIEnv* env, jobject thiz) {
jint temp = 0;
return temp;
}
}
錯誤:
"Compile++ thumb : ccSharedLib <= main-jni.cpp
Reaping winning child 0x012d6098 PID 19632680
Cleaning up temp batch file C:\Users\jpenning\AppData\Local\Temp\make4148-1.bat
CreateProcess(C:\android\ndk\toolchains\arm-linux-androideabi-4.6\prebuilt\windows\bin\arm-linux-androideabi-g++.exe,C:/android/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi/objs/ccSharedLib/main-jni.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fno-exceptions -fno-rtti -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -Iinclude/ -IC:/android/ndk/sources/cxx-stl/system/include -Ijni -DANDROID -Wa,--noexecstack -IC:/android/ndk/platforms/android-14/arch-arm/usr/include -c jni/main-jni.cpp -o ./obj/local/armeabi/objs/ccSharedLib/main-jni.o,...)
Live child 0x12d6098 (obj/local/armeabi/objs/ccSharedLib/main-jni.o) PID 19632680
jni/main-jni.cpp: In function 'jint Java_com_tmz_cc_MainActivity_test1(JNIEnv*, jobject)':
jni/main-jni.cpp:10:23: error: 'FileSync' has not been declared
make: *** [obj/local/armeabi/objs/ccSharedLib/main-jni.o] Error 1
Reaping losing child 0x12d6098 PID 19632680
Removing child 0x12d6098 PID 19632680 from chain.
Soory不起作用。我只有靜態庫。我不能包含.h文件。 'jni/main-jni.cpp:3:22:致命錯誤:FileSync.h:沒有這樣的文件或目錄 編譯終止。' – iAn
您必須**爲您正在嘗試執行的操作提供頭文件(例如,在第三方庫頂部編寫JNI包裝器)。看到這個更多的細節:http://stackoverflow.com/questions/13899481/when-is-a-header-file-required-for-using-a-static-library – deltheil