编译libpng
下载libpng后,放到目录${ANDROID_NDK}/sources/third_party/libpng
方法1: 引入第3方CMake工程
#Import PNG library
set ( png_src_DIR ${ANDROID_NDK}/sources/third_party/libpng )
set ( png_build_DIR ${ANDROID_NDK}/sources/third_party/libpng/outputs )
file(MAKE_DIRECTORY ${png_build_DIR})
#Adds the CMakeLists.txt file located in the specified directory
#as a build dependency.
add_subdirectory( # Specifies the directory of the CMakeLists.txt file.
${png_src_DIR}
# Specifies the directory for the build outputs.
${png_build_DIR} )
#Adds the output of the additional CMake build as a prebuilt static
#library and names it lib_png.
add_library( lib_png STATIC IMPORTED )
set_target_properties( lib_png PROPERTIES IMPORTED_LOCATION
${png_build_DIR}/libpng.a
include_directories( ${png_src_DIR} )
方法2:把代码加入studio 进行编译,修改cmakefile
set ( png_src_DIR ${ANDROID_NDK}/sources/third_party/libpng )
file(GLOB png_SOURCES "${png_src_DIR}/*.c")
##### #exclude example.c pngtest.c
list(REMOVE_ITEM png_SOURCES ${png_src_DIR}/example.c ${png_src_DIR}/pngtest.c)
add_library( # Sets the name of the library.
png
# Sets the library as a shared library.
STATIC
# Provides a relative path to your source file(s).
# Associated headers in the same location as their source
# file are automatically included.
${png_SOURCES})
##### # Specifies a path to native header files.
include_directories(${png_src_DIR})
编译Box2D
下载box2d后,放到目录${ANDROID_NDK}/sources/third_party/box2d
# Import box2d library
set ( box2d_src_DIR
${ANDROID_NDK}/sources/third_party/box2d/Box2D )
set ( box2d_build_DIR
${ANDROID_NDK}/sources/third_party/box2d/Box2D/outputs )
file(MAKE_DIRECTORY ${box2d_build_DIR})
# Adds the CMakeLists.txt file located in the specified directory
# as a build dependency.
add_subdirectory( # Specifies the directory of the CMakeLists.txt file.
${box2d_src_DIR}
# Specifies the directory for the build outputs.
${box2d_build_DIR} )
# Adds the output of the additional CMake build as a prebuilt static
# library and names it lib_box2d.
add_library( lib_box2d STATIC IMPORTED )
set_target_properties( lib_box2d PROPERTIES IMPORTED_LOCATION
${box2d_build_DIR}/Box2D/libBox2D.a)
include_directories( ${box2d_src_DIR} )