目前我正在開發包含其中包括Java和本地C++代碼庫的應用程序。因爲庫項目是一個Eclipse項目,所以我將它導入到Eclipse中,使用「添加本機支持」功能創建了Android.mk和Application.mk,然後將項目重新導入到Android Studio中。如何更新的Android JNI代碼changings
我startet應用程序和它的作品不錯:)但現在,如果我想在做本地C++代碼的一些變化,我認識到,如果我重新啓動該項目,應用程序並沒有顯示這些改變。
我比我從谷歌的解決方案的許多範例項目(例如,「HELLO-JNI」),並有我的changings立即被識別和智能手機上的顯示。
唯一的區別我看到的是Android.mk文件,這是谷歌的例子很簡單,在我的項目庫的情況下,非常大的......只有作爲一個Java開發我覺得有點硬理解,該文件在做什麼以及如何修改它。它看起來像下面。
LOCAL_PATH := $(call my-dir)
$(info TARGET_ARCH_ABI is $(TARGET_ARCH_ABI))
$(info LOCAL_PATH is $(LOCAL_PATH))
PREBUILT_LIBS := $(LOCAL_PATH)/../libs/libraryWithNativeCode/prebuilt/android-$(TARGET_ARCH_ABI)
include $(CLEAR_VARS)
LOCAL_MODULE := libraryWithNativeCode-sdk-lib
LOCAL_SRC_FILES := $(PREBUILT_LIBS)/libraryWithNativeCode-sdk.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := png-lib
LOCAL_SRC_FILES := $(PREBUILT_LIBS)/libpng.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../libs/libraryWithNativeCode/png
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := curl-lib
LOCAL_SRC_FILES := $(PREBUILT_LIBS)/libcurl.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../libs/libraryWithNativeCode/curl/android-$(TARGET_ARCH_ABI)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := ssl-lib
LOCAL_SRC_FILES := $(PREBUILT_LIBS)/libssl.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := crypto-lib
LOCAL_SRC_FILES := $(PREBUILT_LIBS)/libcrypto.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := http-parser-lib
LOCAL_SRC_FILES := $(PREBUILT_LIBS)/libhttp-parser.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../libs/libraryWithNativeCode/http-parser
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := jpeg-lib
LOCAL_SRC_FILES := $(PREBUILT_LIBS)/libjpeg.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := turbojpeg-lib
LOCAL_SRC_FILES := $(PREBUILT_LIBS)/libturbojpeg.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../libs/libraryWithNativeCode/jpeg-turbo
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libraryWithNativeCode-mobile-example-app
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2 -lz -lm
LOCAL_LDLIBS += -fuse-ld=bfd
LOCAL_STATIC_LIBRARIES := libraryWithNativeCode-sdk-lib png-lib curl-lib ssl-lib crypto-lib http-parser-lib jpeg-lib turbojpeg-lib android_native_app_glue ndk_helper
LOCAL_CFLAGS += -Wall -Wno-unknown-pragmas -Wno-sign-compare -Wno-format-security -Wno-reorder
#LOCAL_CFLAGS += -Werror
ifdef COMPILE_CPP_11
$(info Configured for C++11)
LOCAL_CPPFLAGS += -DCOMPILE_CPP_11=1 -std=c++11
else
$(info Configured for C++0x)
endif
os_name:=$(shell uname -s)
get_android_cpp_files_cmd := find $(LOCAL_PATH) -type f -iname "*.cpp"
get_android_includes_cmd := find $(LOCAL_PATH) -type d
get_shared_cpp_files_cmd := find $(LOCAL_PATH)/src -type f -iname "*.cpp"
get_shared_includes_cmd := find $(LOCAL_PATH)/src -type d
get_platform_includes_cmd := find $(LOCAL_PATH)/../libs/libraryWithNativeCode/platform -type d ! -path "*/OSX/*" ! -path "*/iOS/*"
ifeq ($(os_name),Darwin)
cppfiles := ${shell ${get_android_cpp_files_cmd}}
cppfiles += ${shell ${get_shared_cpp_files_cmd}}
includes := ${shell ${get_android_includes_cmd}}
includes += ${shell ${get_shared_includes_cmd}}
includes += ${shell ${get_platform_includes_cmd}}
else
# assume windows if not specified for now (due to no uname)
cppfiles := ${shell sh -c '${get_android_cpp_files_cmd}'}
cppfiles += ${shell sh -c '${get_shared_cpp_files_cmd}'}
includes := ${shell sh -c '${get_android_includes_cmd}'}
includes += ${shell sh -c '${get_shared_includes_cmd}'}
includes += ${shell sh -c '${get_platform_includes_cmd}'}
endif
LOCAL_SRC_FILES := $(cppfiles:$(LOCAL_PATH)/%=%)
LOCAL_C_INCLUDES := $(includes)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../libs/libraryWithNativeCode/rapidjson
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../libs/libraryWithNativeCode/rapidjson/internal
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
$(call import-module,android/ndk_helper)
我的文件夾結構是這樣的:
- Android_Studio_Project
--.gradle
--.idea
--app
---src
----main (etc)
--libraryProjectWithNativeCode
---src
----main
-----java (contains the java code)
-----jni (contains the jni code)
-----jniLibs
-----etc.
--build.gradle etc.
任何人的想法如何解決這個問題呢?感謝提前:)
你好MSalters,你是對的$(cppfiles)包含了所有的我的源文件,我只是編輯從哪裏文件包含的路徑,但是當我打電話'NDK-build'我現在得到的錯誤我的一個包含語句無法找到:'Types.h:沒有這樣的文件或目錄......有關我如何解決這個問題的任何想法? – jennymo
這就是'$(includes)'的用途。 – MSalters
哦,是的,很明顯。我搜索了我的文件夾中的Types.h,並找到它,我用來保存到$(includes)變量中的路徑也是正確的。該文件位於文件夾「/ Users/jenny/appproject/libraryProjectWithNativeCode/src/main/jniLibs/platform」中。我打印了我的'$(includes)'變量,路徑被列在其中......但是錯誤仍然存在...... – jennymo