Cannot import libpng, libjpeg in ndk android - 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.

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

Related

How do I build the arcore camera_utility shared library in NDK-BUILD?

I'm trying to build the 'arcore camera utility' library in NDK_BUILD, here: https://github.com/google-ar/arcore-unity-sdk/tree/master/Assets/GoogleARCore/Examples/ComputerVision/Plugins/src
Using this guide: https://yeephycho.github.io/2016/10/20/How-to-Use-NDK-to-Build-A-Shared-Android_Native-Library/ I was at least able to get it to compile in a libarcore_camera_utility.so file. Not only that but it was actually recognized by my app on the phone and instead of getting a DLL missing error I got the error: "EntryPointNotFoundException: Unable to find an entry point named 'TextureReader_create' in 'arcore_camera_utility'." which means it at least found the file, now.
The filesize of the .so is only 6k so it seems like I'm not compiling it correctly as the already working 32bit version that comes with the package is 100k, based on this question it seems like I'm leaving something out?: Entry point not found, Android .so file
My Android.mk file is:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := arcore_camera_utility_shared
LOCAL_C_INCLUDES += \
LOCAL_SRC_FILES := camera_utility.cc gl_utility.cc texture_reader.cc
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := arcore_camera_utility
LOCAL_WHOLE_STATIC_LIBRARIES := arcore_camera_utility_shared
include $(BUILD_SHARED_LIBRARY)
And my Application.mk file contains:
APP_ABI := arm64-v8a
APP_PLATFORM := android-24
APP_STL := c++_static
APP_BUILD_SCRIPT := ./jni/Android.mk
Am I building it in such a way as to leave the code out?
To compile arcore_camera_utility for the arm 64bit target-
1.) Create a new directory called 'arcorelibrary', then a subdirectory called 'jni'
2.) Download this zip: https://github.com/google-ar/arcore-unity-sdk/blob/master/Assets/GoogleARCore/Examples/ComputerVision/Plugins/src/arcore_camera_utility.zip
3.) get the three .cc files and the three .h files and place them in the jni directory
4.) Create a file called 'Android.mk' and place it in the jni directory, with the following contents:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= arcore_camera_utility_static
LOCAL_SRC_FILES:= camera_utility.cc gl_utility.cc texture_reader.cc
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
LOCAL_EXPORT_LDLIBS := -llog -landroid -lEGL -lGLESv2 -lGLESv3
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := arcore_camera_utility
LOCAL_WHOLE_STATIC_LIBRARIES := arcore_camera_utility_static
include $(BUILD_SHARED_LIBRARY)
5.) Create a file called 'Application.mk' and place it in the jni directory, with the following contents:
APP_ABI := arm64-v8a
APP_PLATFORM := android-24
APP_STL := c++_static
APP_BUILD_SCRIPT := ./jni/Android.mk
6.) Download Android NDK and unzip somewhere (The version you need depends on which Unity version you're using) https://developer.android.com/ndk/downloads/older_releases.html
7.) Open a terminal or powershell, go to the root directory (arcorelibrary) of your project
8.) Create a path to where ever you unzipped Android NDK (Powershell example):
$env:Path += ";C:\[where-ever-you-unzipped]\android-ndk-r13b-windows-x86_64\android-ndk-r13b"
9.) Run:
ndk-build.cmd

Specify directory for external C++ library +NDK +Android studio

I'm new to this NDK build and I'm having trouble with running this Buildbox project in android studio.
After linking C++ to Gradle using ndk-build and syncing, it is giving this error.
Android NDK: C:\AndroidApps\app\app\src\main\jni\Android.mk: Cannot find module with tag 'box2D' 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:
process_begin: CreateProcess(NULL, "", ...) failed.
I can see reference for cocos2dx in the java and resources subfolders.
I'm not sure if I have to download box2D,core,cocos2dx library .
What changes do I have to make to the android.mk file so that the errors are gone?
Here is the android.mk file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := player_shared
LOCAL_MODULE_FILENAME := libplayer
LOCAL_SRC_FILES := main.cpp
LOCAL_WHOLE_STATIC_LIBRARIES := core_static cocos2dx_static box2d_static
GOOGLE_PLAY_STORE := true
include $(BUILD_SHARED_LIBRARY)
$(call import-add-path, $(LOCAL_PATH)/platform/third_party/android/prebuilt)
$(call import-module, box2D)
$(call import-module, core)
$(call import-module, cocos2dx)
NDK does not download imported modules for you. I am not sure if there are plans to add such feature (parallel to XCode pods) in the future.
You will find detailed description of import-module here, but basically you can set NDK_MODULE_PATH in your Application.mk file, with ; separators on Windows, but using straight / in paths instead of Windows native backsashes, e.g. C:/ext), and then
$(call import-module, box2D)
will be equivalent to
include C:/ext/box2D/Android.mk

Not able to build Android NDK project fatal error: android/configuration.h: No such file or directory compilation terminated

I am building a complete native app in using Android NDK, when I try to build the app I am getting the following error:
D:/Softwares/android-ndk-r9c/sources/android/native_app_glue/android_native_app_glue.h:25:35: fatal error: android/configuration.h: No such file or directory compilation terminated.
I am not getting why this error is coming. I have created an Android.mk file with following content
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := mynativeactivity
LOCAL_SRC_FILES := Log.cpp Main.cpp EventLoop.cpp
LOCAL_LDLIBS := -llog -landroid
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
Also, in the project properties I have added following Paths & Symbols
D:/Softwares/android-ndk-r9c/platforms/android-9/arch-arm/usr/include
D:/Softwares/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.8/include
D:/Softwares/android-ndk-r9c/sources/android/native_app_glue
Can anyone suggest what am I doing wrong ?
LOCAL_LDLIBS := -landroid is the problem.
The system is expecting the configuration.h file, as simple as that.
Why do you mean by project properties ? in eclipse ? .
ndk-build would not pick your ecplise project properties.
Please add Application.mk file and mention the APP_PLATFORM := android-9 ( not sure if it should solve the problem).Otherwise , add the include path LOCAL_C_INCLUDES in your android.mk file.

Static Linking OpenCV 2.4.3.2

I would like to statically link OpenCV(2.4.3.2) to my project. Right now my Android.mk looks like this
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
include /Users/jamiematthews/Documents/Android-Projects/OpenCV-2.4.3-android-sdk/sdk/native/jni/OpenCV.mk
LOCAL_MODULE := jni_part
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_LDLIBS += -llog -ldl
LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog
include $(BUILD_SHARED_LIBRARY)
Which throws the errors:
Android NDK: ERROR:/Users/jamiematthews/Documents/workspace/AuthentiGuard/jni/Android.mk:on: LOCAL_SRC_FILES points to a missing file
/Users/jamiematthews/Documents/android-ndk-r8d/build/core/prebuilt-library.mk:43: *** Android NDK: Aborting . Stop.
Android NDK: Check that /Users/jamiematthews/Documents/Android-Projects/OpenCV-2.4.3-android-sdk/sdk/native/jni/../libs/mips/libon.so exists or that its path is correct
Anyone know what "LOCAL_SRC_FILES points to a missing file" could mean?
PS if I remove the lines
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
it compiles fine, but then I cant statically link
Found the solution. Believe it or not it was an issue with Application.mk, not Android.mk. I had set
APP_ABI := all
Previously, and not even considered that it could effect the build process of this statically. I ended up changing it to
APP_ABI := armeabi-v7a
And now, everything works fine. Note that I ended up not needing OPENCV_CAMERA_MODULES:=on, I believe that is only if you are calling the camera from JNI, which I am not
LOCAL_SRC_FILES show the file where your native code resides. If you use native OpenCV code then you have to add the name of your cpp file here.
If you do not have a native part then you should add the OpenCV library to the libs folder of your project. (in case of static initialization). Please check this page for details.

Cannot find module in import path error

I have some of my own C++ code compiling and running fine using the NDK. As I can't see any way to access the libpng library that is built into Android, my only option seems to be to compile my own version and use that (I'd be interested to know about alternatives).
I'm currently trying to extend my code to make use of libpng. I can't work out how to get my code to build. I've read the docs and scoured through newsgroup question and answers but I can't resolve my problem.
I've copied libpng to my source tree. I'm trying to compile libpng as a static library and then have my code use this to access libpng's functions. Here is what I have so far for my make files:
########## Directory layout ##########
jni/
Android.mk
mylib/
Android.mk
source files...
libpng/
Android.mk
source files...
########## Top-level Android.mk ##########
LOCAL_PATH := $(call my-dir)
include $(LOCAL_PATH)/libpng/Android.mk
include $(LOCAL_PATH)/mylib/Android.mk
########## mylib Android.mk ##########
include $(CLEAR_VARS)
NDK_MODULE_PATH := $(LOCAL_PATH)
LOCAL_STATIC_LIBRARIES := libpng
LOCAL_C_INCLUDES := $(LOCAL_PATH)/libpng
LOCAL_LDLIBS := -llog
LOCAL_MODULE := mylib
LOCAL_CFLAGS :=
sources := mylib.cpp
LOCAL_SRC_FILES += $(sources:%=mylib/%)
include $(BUILD_SHARED_LIBRARY)
$(call import-module, libpng)
########## libpng Android.mk ##########
include $(CLEAR_VARS)
LOCAL_CFLAGS :=
LOCAL_MODULE := libpng
sources :=\
png.c \ # etc.
LOCAL_SRC_FILES += $(sources:%=libpng/%)
LOCAL_LDLIBS := -lz
include $(BUILD_STATIC_LIBRARY)
mylib is my code that already compiles if I remove all the libpng material. libpng will compile successfully on its own as well. Notice I'm keeping my code and the libpng code in separate directories and trying to use a top-level make file to compile these.
The current error message that I'm stuck on when attempting to build mylib is:
Cannot find module with tag 'libpng' in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?
I've set NDK_MODULE_PATH to $(LOCAL_PATH) which I believe means the build process should find libpng/Android.mk but it doesn't. Can anyone help?
Try with LOCAL_MODULE := png instead of libpng

Categories

Resources