libpng编译-android端(libpng官网下载是没有android编译脚本)
环境配置(mac的原理一样可以自己配置,我在linux编译)
配置ubuntu的ndk环境
1、执行 sudo vim /etc/profile,对Path的路径文件进行更改(如果vim系统没有安装的话,使用vi替换) 如果提示
export ANDROID_SDK=/home/shenjianbin/baoyu45585/android-ndk-r14b
export PATH=${PATH}:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools
export ANDROID_NDK=/home/shenjianbin/baoyu45585/android-ndk-r14b
export PATH=$ANDROID_NDK:$PATH
export ANDROID_NDK_R14=/home/shenjianbin/baoyu45585/android-ndk-r14b
分别执行执行
source /etc/profile
ndk-build -v
libpng-1.6.40编译
官网版本
libpng下载地址,可以点击选择自己版本
官网下载后版本已经删除多余文件和增加对应编译文件,已经可以直接用
libpng-1.6.40编译完整版下载
对应编译文件编写分别是Android.mk、Application.mk、build.sh,在对应终端可以执行./build.sh
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libpng16
LOCAL_SRC_FILES :=\
png.c \
pngerror.c \
pngget.c \
pngmem.c \
pngpread.c \
pngread.c \
pngrio.c \
pngrtran.c \
pngrutil.c \
pngset.c \
pngtest.c \
pngtrans.c \
pngwio.c \
pngwrite.c \
pngwtran.c \
pngwutil.c \
arm/arm_init.c \
arm/filter_neon.S \
arm/filter_neon_intrinsics.c \
arm/palette_neon_intrinsics.c
# 设置头文件路径
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
# 添加需要链接的库(如果有)
#LOCAL_LDLIBS := -lz
# 设置输出包含文件夹
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
# 创建输出包含文件夹
$(shell mkdir -p $(LOCAL_PATH)/include)
# 拷贝所需文件到输出文件夹
$(shell cp $(LOCAL_PATH)/png.h $(LOCAL_PATH)/include)
$(shell cp $(LOCAL_PATH)/pngconf.h $(LOCAL_PATH)/include)
$(shell cp $(LOCAL_PATH)/pnglibconf.h $(LOCAL_PATH)/include)
include $(BUILD_STATIC_LIBRARY)
Application.mk
APP_OPTIM := release
APP_PLATFORM := android-18
APP_ABI := armeabi-v7a arm64-v8a x86_64 # or all
APP_MODULES := libpng16
NDK_TOOLCHAIN_VERSION=4.9
APP_PIE := false
APP_CFLAGS := -O3 -Wall -pipe \
-ffast-math \
-fstrict-aliasing -Werror=strict-aliasing \
-Wno-psabi -Wa,--noexecstack \
-DANDROID -DNDEBUG
build.sh
ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk NDK_APPLICATION_MK=./Application.mk
执行命令,会生成相应文件
./build.sh