11

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?

Delfigamer
  • 317
  • 1
  • 8
Misha Ponomarev
  • 111
  • 1
  • 1
  • 3

1 Answers1

16

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!

bricklore
  • 4,125
  • 1
  • 34
  • 62
  • 2
    Thanks a lot for your answer but it is not what I want. I have to send my project to the company. I don't think that it will be polite to tell them what they have to do to make my project work - I mean copying files in android_ndk_folder and so on. They gonna just compile it so all necessary files are need to be included inside the project. – Misha Ponomarev Jan 14 '13 at 20:10
  • 3
    This will only work for ARM devices, and then only the old ones. You're missing MIPS, 64-bit ARM, x86, 64-bit x86, ARM with floating point units, ... – dascandy Aug 30 '15 at 10:19
  • This worked like a charm building on a Widnwos dev...it also worked with older versions of libpng. Tested with 1.4.19. Simply download from the official site and copy/paste the Android and Application.mk files to the downloaded folder and run ndk-build – velval Oct 18 '16 at 22:38