Android ndk port c Library libpng

Source: Internet
Author: User

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)
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.