Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding libpng in android ndk project

I've searched a lot of topics about linking libpng to my android ndk project but I've found right answer for my problem and I hope somebody will help me.

This is hierarchy of my project:

jni

different_cpp_files
different_hpp_files
Android.mk
libpng
    different_cpp_files
    different_hpp_files
    Android.mk

Android.mk in libpng folder:


LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LS_C=$(subst $(1)/,,$(wildcard $(1)/*.c))

LOCAL_MODULE := png

LOCAL_SRC_FILES := \

$(filter-out example.c pngtest.c,$(call LS_C,$(LOCAL_PATH)))

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)

LOCAL_EXPORT_LDLIBS := -lz

include $(BUILD_STATIC_LIBRARY)

I suppose that everything is right here..

Android.mk in jni folder:


LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LS_CPP=$(subst $(1)/,,$(wildcard $(1)/*.cpp))

LOCAL_MODULE    := pacman

LOCAL_CFLAGS    := -Wno-psabi

LOCAL_SRC_FILES := $(call LS_CPP,$(LOCAL_PATH))

LOCAL_LDLIBS    := -landroid -llog -lEGL -lGLESv1_CM -lOpenSLES

LOCAL_STATIC_LIBRARIES := android_native_app_glue png

include $(BUILD_SHARED_LIBRARY)

$(call import-module,android/native_app_glue)

$(call import-module,libpng)

The last line shows that I got libpng like native_app_glue lib(in the directory of android-ndk sources) Now I want to compile libpng from my project. What I need to change in Android.mk file?

like image 397
Misha Ponomarev Avatar asked Jan 10 '13 16:01

Misha Ponomarev


1 Answers

i've got another way for you:

  1. Download all files from here and paste it into a new folder anywhere on your system:
    https://github.com/julienr/libpng-android

  2. go into the folder and run:
    ./build.sh

  3. You will get an libpng.a file in [YOUR_FOLDER]/obj/local/armeabi/libpng.a
    Copy this file into:
    [YOUR_ANDROID_NDK_FOLDER]/platforms/[ALL_FOLDERS_IN_HERE]/arch-arm/usr/lib/

  4. now you can use libpng in all your projects with the simple line:
    LOCAL_LDLIBS += -lpng

  5. you only have to include this in your cpp's:
    #include <png.h>

Have fun!

like image 59
bricklore Avatar answered Sep 27 '22 15:09

bricklore