1. download the libpng library on the libpng official website and decompress it.
2. view the contents of makefile. Create a folder to view the files that must be included in the makefile file compiled into the library and copy them to the file. Here, the file name is png.
The following is a complete description of the libpng1510 makefile file containing all the statements required to compile the libpng library.
OBJS = png. o pngset. o pngget. o pngrutil. o pngtrans. o pngwutil. o \
Pngread. o pngrio. o pngwio. o pngwrite. o pngrtran. o \
Pngwtran. o pngmem. o pngerror. o pngpread. o
(. O files are necessary intermediate files for compiling and generating link libraries)
3.1 (there are multiple methods here. 3.1 represents the 1st methods in step 3 .) Compile it into a so file or. a file (dynamic or static Link Library File) and then transplant it to the project. You can refer to the android-mk.html document under the docsfolder in ndk.
3.1.1 (3.1 represents the first step of the 1st methods in step 3 .) : You can create a jni folder, then throw the png folder to the jni folder, and then create a. mk file. The content is as follows:
Static
LOCAL_PATH: = $ (call my-dir)
Include $ (CLEAR_VARS)
LOCAL_MODULE: = png
LOCAL_SRC_FILES: = png/png. c png/pngset. c png/pngget. c png/pngrutil. c png/pngtrans. c png/pngwutil. c \
Png/pngread. c png/pngrio. c png/pngwio. c png/pngwrite. c png/pngrtran. c \
Png/pngwtran. c png/pngmem. c png/pngerror. c png/pngpread. c
Include $ (BUILD_STATIC_LIBRARY)
Dynamic
LOCAL_PATH: = $ (call my-dir)
Include $ (CLEAR_VARS)
LOCAL_MODULE: = png
LOCAL_SRC_FILES: = png/png. c png/pngset. c png/pngget. c png/pngrutil. c png/pngtrans. c png/pngwutil. c \
Png/pngread. c png/pngrio. c png/pngwio. c png/pngwrite. c png/pngrtran. c \
Png/pngwtran. c png/pngmem. c png/pngerror. c png/pngpread. c
Include $ (BUILD_SHARED_LIBRARY)
(Of course, you can directly remove the files in the file and put them under jni without adding png/to the folder)
3.1.2: If you have decompressed the ndk, add the ndk directory to the environment variable, and then you can enter the directory on the top layer of jni. Ndk-build. In this case, you can get the desired Link Library in the newly generated libs and obj folders. (If you are using static files, the libs Folder does not exist. Because the items in the libs folder will be directly packaged into the apk in the future. The static link library is not automatically packaged in it and can only be packaged in a dynamic library .)
3.1.3: after obtaining the link library, you can use it in your ndk project! At this time, you need to copy your dynamic link library directly to the jni folder of your project. Then write the following mk file:
LOCAL_PATH: = $ (call my-dir)
Include $ (CLEAR_VARS)
LOCAL_MODULE: = png
LOCAL_SRC_FILES: = libpng. so
# Include $ (BUILD_STATIC_LIBRARY) # If a static library is used, remove the statement before include #
# Include $ (BUILD_SHARED_LIBRARY) # Remove this statement before include if a dynamic library is used
Include $ (CLEAR_VARS)
LOCAL_MODULE: = ourproject
LOCAL_SRC_FILES: = ourproject. c
# LOCAL_STATIC_LIBRARIES: = libpng # If the static library is used, remove the one before the include statement #
# LOCAL_SHARED_LIBRARIES: = libpng # If a dynamic library is used, remove the one before the include statement #
Include $ (BUILD_SHARED_LIBRARY)
After compilation, You Can CD to your project path and then ndk-build. In your ourproject. c
File.
3.2: Okay, this is 2nd. You do not need to have a dynamic link library first. You only need to follow the steps below.
3.2.1 copy the png folder directly to the jni folder of your project. Then write the following mk file directly.
LOCAL_PATH: = $ (call my-dir)
Include $ (CLEAR_VARS)
LOCAL_MODULE: = png
LOCAL_SRC_FILES: = png/png. c png/pngset. c png/pngget. c png/pngrutil. c png/pngtrans. c png/pngwutil. c \
Png/pngread. c png/pngrio. c png/pngwio. c png/pngwrite. c png/pngrtran. c \
Png/pngwtran. c png/pngmem. c png/pngerror. c png/pngpread. c
# Include $ (BUILD_STATIC_LIBRARY) # If a static library is used, remove the statement before include #
# Include $ (BUILD_SHARED_LIBRARY) # Remove this statement before include if a dynamic library is used
Include $ (CLEAR_VARS)
LOCAL_MODULE: = ourproject
LOCAL_SRC_FILES: = ourproject. c
# LOCAL_STATIC_LIBRARIES: = libpng # If the static library is used, remove the one before the include statement #
# LOCAL_SHARED_LIBRARIES: = libpng # If a dynamic library is used, remove the one before the include statement #
Include $ (BUILD_SHARED_LIBRARY)