做项目的过程中发现,引用第三方的库lib3rdsdk.so,当直接把lib3rdsdk.so放进armeabi文件夹里,会被删除掉。查网上资料都说的不全,经过实验,最简单的方法就是在jni下的android.mk里加下面3-7行就可以,要放最前面,放后面有可能不行哦,因为编译路径有可能会被改掉。
其中prebuilt/$(TARGET_ARCH_ABI)中的prebuilt就是jni里新建的prebuilt文件,其实建不建无所谓,prebuilt里面有4个文件夹:armeabi、armeabi-v7a、mips、x86,每个文件夹里放着不同架构的lib3rdsdk.so库, $(TARGET_ARCH_ABI)则是按cpu架构自动选择armeabi、armeabi-v7a、mips、x86这些架构中的库,默认只会复制armeabi中的libtxpay.so库,比如需要多复制armeabi-v7a中的库,则需要在application.mk中添加APP_ABI := armeabi armeabi-v7a后,则会同时复制armeabi armeabi-v7a的库
01 | LOCAL_PATH := $(call my-dir) |
07 | LOCAL_SRC_FILES := prebuilt/$(TARGET_ARCH_ABI)/lib3rdsdk.so |
09 | include $(PREBUILT_SHARED_LIBRARY) |
13 | LOCAL_MODULE := game_shared |
15 | LOCAL_MODULE_FILENAME := libgame |
17 | #traverse all the directory and subdirectory |
21 | $(wildcard $( 1 )) $(foreach e, $(wildcard $( 1 )/*), $(call walk, $(e))) |
25 | #traverse Classes Directory |
27 | ALLFILES = $(call walk, $(LOCAL_PATH)/../../Classes) |
29 | FILE_LIST := hellocpp/main.cpp |
31 | FILE_LIST += $(LOCAL_PATH)/../../Classes/helloworld.cpp |
33 | FILE_LIST += $(filter %.cpp, $(ALLFILES)) |
35 | FILE_INCLUDES := $(shell find $(LOCAL_PATH)/../../Classes -type d) |
37 | #source file will be compiled |
39 | LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%) |
41 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../external/Box2D/ \ |
46 | LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static box2d_static |
48 | include $(BUILD_SHARED_LIBRARY) |
50 | $(call import -module,CocosDenshion/android) \ |
52 | $(call import -module,cocos2dx) \ |
54 | $(call import -module,extensions) \ |
56 | $(call import -module,external/Box2D) |