3

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.

Jerin A Mathews
  • 8,572
  • 4
  • 26
  • 49
  • Why have you got `CImg` tag here? – Mark Setchell Jul 02 '18 at 16:06
  • The library uses CImg. And the libpng and libjpeg is for CImg. So i would like to know, if anyone used CImg and imported libpng and libjpeg successfully, – Jerin A Mathews Jul 02 '18 at 16:29
  • Ah ok, I see. Sorry I can't help - you are beyond the limits of my knowledge! – Mark Setchell Jul 02 '18 at 16:33
  • Oh ok. I was trying to solve this for two days, and I cant. So frustrated. I know it's not easy, cause there's no good solution given anywhere online. It seems easy, but so hard to solve. – Jerin A Mathews Jul 02 '18 at 16:37
  • a) Have you installed `libpng`? b) Can you find exactly **where** `libpng` is installed - i.e. which directory? c) Can you manually add the full, explicit path to the directory containing `libpng` into your build rather than hoping `import-module` might find it for you? Just some mad ideas... :-) – Mark Setchell Jul 02 '18 at 16:40
  • In one of the methods I tried, I installed libpng and got the path. It did not work. But can you tell me how to "manually add the full, explicit path to the directory containing libpng into your build". Just to confirm, since am kind of new in NDK. – Jerin A Mathews Jul 02 '18 at 16:52
  • I have no experience with Android but that looks like a Makefile. So, as a test, you could add `-ljpeg -llibpng` and `-L/path/to/directory/containing/libraries` after `-lz` – Mark Setchell Jul 02 '18 at 17:47

1 Answers1

4

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

Jerin A Mathews
  • 8,572
  • 4
  • 26
  • 49
  • sorry for English. I am also using ndk first time and using ucrop too. And I have to modify ndk to support mips, mips64. Could you please tell me which version of ndk do you use?( I tried r10e, r11c, r12b, r13b) my error from r13b is jni/CImg.h:275:10: fatal error: 'omp.h' file not found #include other's error is jni/CImg.h:321:21: fatal error: jpeglib.h: No such file or directory #include "jpeglib.h" – Soo Chun Jung Nov 01 '18 at 10:54
  • @SooChunJung I used the ndk , within the android studio, i believe its r16 – Jerin A Mathews Nov 01 '18 at 13:53
  • build success! Thank you so much :) – Soo Chun Jung Nov 02 '18 at 01:16
  • Great, Happy it helped :) – Jerin A Mathews Nov 02 '18 at 04:15
  • 1
    I got following error : Cannot find module with tag 'libpng/jni' in import path – Ashish Garg Sep 04 '20 at 14:00