Jerin A Mathews
Jerin A Mathews

Reputation: 8712

Cannot import libpng, libjpeg in ndk android

I forked, Ucrop library for cropping, and made some changes. Now i have to build the ndk to make the changes. But am keep getting this error:

 Android NDK: jni/Android.mk: Cannot find module with tag 'libpng' in import path    
 Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?    
 Android NDK: The following directories were searched:    
 Android NDK: jni/Android.mk:15: *** Android NDK: Aborting.    .  Stop.

The project uses Cimg library.

This is my Android.mk file:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE    := ucrop
LOCAL_SRC_FILES := uCrop.cpp

LOCAL_LDLIBS    := -landroid -llog -lz
LOCAL_STATIC_LIBRARIES := libpng libjpeg_static

include $(BUILD_SHARED_LIBRARY)

$(call import-module,libpng)
$(call import-module,libjpeg)

I tried all solutions that given online. But nothing worked. I tried "Adding libpng in android ndk project" and many answers.

Upvotes: 3

Views: 1097

Answers (1)

Jerin A Mathews
Jerin A Mathews

Reputation: 8712

Atlast I made it work. It was hard because I was a beginner in NDK. But i will post how i did it in here, since it may help other beginners.

First I download libpng and libjpeg, and saved it under Android/Sdk/ndk-bundle/sources. I saved those under names, libpng and libjpeg respectively.

Then modify Android.mk as below,

LOCAL_PATH := $(call my-dir)

LOCAL_P := /usr/lib/

include $(CLEAR_VARS)

LOCAL_MODULE    := ucrop
LOCAL_SRC_FILES := uCrop.cpp

LOCAL_LDLIBS    := -landroid -llog -lz
LOCAL_STATIC_LIBRARIES := libpng libjpeg9

include $(BUILD_SHARED_LIBRARY)

$(call import-module,libpng/jni)
$(call import-module,libjpeg/libjpeg9)

Then set environment path NDK_MODULE_PATH as below,

export NDK_BUILD_PATH=/home/jerin/Android/Sdk/ndk-bundle/sources

This is important since, during ndk build, it looks for the libraries in this path.

You can compile ndk-build during gradle build by following [this][1]. Right-click on the module you would like to link to your native library, such as the app module, and select Link C++ Project with Gradle from the menu. Then select ndk-build, and give path to Android.mk

Upvotes: 4

Related Questions