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

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

Related

MSI SDR device sample code does not compile

I am trying to interface with an MSI SDR dongle, using an android app
This device is a clone of the SDRPlay SDR device, and is compatible with it's software and drivers
I am trying to interface with this using an OTG cable and android phone
The android drivers for this can be downloaded from here https://www.sdrplay.com/downloads/
It is in the Android tab under the API/HW – V2.11 (15TH NOV 2017) link (https://www.sdrplay.com/anddl.php)
A possible sample code for this driver can be found here: https://www.sdrplay.com/docs/AndroidIntegrationNote.pdf
Before making the full android program it says the library (libmir_sdr_api.a) should be built into an .so library file using ndk-build
I currently have Android's hello-jni sample project from here: https://github.com/android/ndk-samples/tree/android-mk/hello-jni
I have replaced the jni folder using the Android.mk file, libmir_sdr_api.a, mir_sdr.h, initialization-jni.cpp, demod-jni.cpp and demod-jni.h files mentioned in section 3 of the AndroidIntegrationNote.pdf file I linked above
When I execute ndk-build from the hello-jni project folder, I get he following error:
Android NDK: Found platform level in ./default.properties. Setting APP_PLATFORM to android-25.
Android NDK: android-25 is an alias for android-24. Adjusting APP_PLATFORM to match.
[arm64-v8a] Gdbserver : [aarch64-linux-android] libs/arm64-v8a/gdbserver
[arm64-v8a] Gdbsetup : libs/arm64-v8a/gdb.setup
[x86_64] Gdbserver : [x86_64-linux-android] libs/x86_64/gdbserver
[x86_64] Gdbsetup : libs/x86_64/gdb.setup
[armeabi-v7a] Gdbserver : [arm-linux-androideabi] libs/armeabi-v7a/gdbserver
[armeabi-v7a] Gdbsetup : libs/armeabi-v7a/gdb.setup
[x86] Gdbserver : [i686-linux-android] libs/x86/gdbserver
[x86] Gdbsetup : libs/x86/gdb.setup
make: *** No rule to make target 'jni/initialisation-jni.cpp', needed by 'obj/local/arm64-v8a/objs-debug/mirics-jni/initialisation-jni.o'. Stop.
I am used to compiling NDK code suing Android Studio and cmake so I am not sure what is going on here. I have not been able to link the .a file through cmake either so I thought of giving the driver manufacturer's sample code a try, but it not working either. Is the Android.mk file in pdf file linked earlier incomplete, or am I not building it correctly? These are the contents of the Android.mk file:
# $(call my-dir) returns the local directory which is the jni directory
LOCAL_PATH := $(call my-dir)
# libmir_sdr_api.a – this section creates a version of the Mirics API to be used below
include $(CLEAR_VARS)
LOCAL_MODULE := mir_sdr_api-prebuilt
LOCAL_SRC_FILES := libmir_sdr_api.a
LOCAL_EXPORT_C_INCLUDES := $(call my-dir)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
# mirics-jni – this section uses the jni C++ source code to build the dynamic library
LOCAL_MODULE := mirics-jni
LOCAL_SRC_FILES := initialisation-jni.cpp demod-jni.cpp
LOCAL_C_INCLUDES := $(call my-dir)
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib
LOCAL_STATIC_LIBRARIES := mir_sdr_api-prebuilt
include $(BUILD_SHARED_LIBRARY)
Regarding missing jni/initialisation-jni.cpp, you probably have the file jni/initialization-jni.cpp instead.
Also, unfortunately, the document is wrong. You can only use $(call my-dir) easily at the top of the file. Luckily, Android NDK adds the jni directory to includes path for you. Still, to be on the safe side, better write:
# $(call my-dir) returns the local directory which is the jni directory
LOCAL_PATH := $(call my-dir)
# libmir_sdr_api.a – this section creates a version of the Mirics API to be used below
include $(CLEAR_VARS)
LOCAL_MODULE := mir_sdr_api-prebuilt
LOCAL_SRC_FILES := libmir_sdr_api.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
# mirics-jni – this section uses the jni C++ source code to build the dynamic library
LOCAL_MODULE := mirics-jni
LOCAL_SRC_FILES := initialization-jni.cpp demod-jni.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib
LOCAL_STATIC_LIBRARIES := mir_sdr_api-prebuilt
include $(BUILD_SHARED_LIBRARY)
Finally, pay attention to your build process. You only have one kind of the libmir_sdr_api.a static library, it's built for a 32-bit ARM CPU. Therefore you cannot build your libmirics-jni.so for other architectures. Add
APP_ABIS = armeabi-v7a
to your Application.mk file, or specify
abifilters = armeabi-v7a
in your build.gradle, if you build your library in Android Studio.

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.
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

NDK unable to find my module in the NDK_MODULE_PATH - android-ndk-profiler

I am trying to use android-ndk-profiler - https://github.com/richq/android-ndk-profiler
As described in the usage document https://github.com/richq/android-ndk-profiler/blob/master/docs/Usage.md
I unzipped the zip file to $HOME/Documents/Dev
My Android.mk looks like this
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ndkbasics
LOCAL_SRC_FILES := ndkbasics.cpp
LOCAL_LDLIBS := -llog
# compile with profiling
LOCAL_CFLAGS := -pg
LOCAL_STATIC_LIBRARIES := android-ndk-profiler
include $(BUILD_SHARED_LIBRARY)
# at the end of Android.mk
$(call import-module,android-ndk-profiler)
When trying to build using the command
ndk-build NDK_MODULE_PATH=$HOME/Documents/Dev/
I get the error
Android NDK: /Users/hanantha/Documents/Dev/projects/workspaceWeeklyPreso/NdkProfileMethods/jni/Android.mk: Cannot find module with tag 'android-ndk-profiler' 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:
/Users/hanantha/Documents/Dev/projects/workspaceWeeklyPreso/NdkProfileMethods/jni/Android.mk:16: *** Android NDK: Aborting. . Stop.
Additional points
I have tried setting NDK_MODULE_PATH in my bash_profile
ndk version r10d
Ran the make file in the unzipped folder android-ndk-profiler
It is strange that ndk says the directories that it has searched is empty. What could be going wrong?
I think you have done almost correct process need to change at one place as follow
# at the end of Android.mk
$(call import-module,android-ndk-profiler/jni)
Adding jni in import-module will solve your problem because it's working for me.

How to build Android NDK cocos2d-x project from within Eclipse?

I set up an Android project that uses cocos2d-x. Now I want to build the project in Eclipse but I get the build error
Android NDK: jni/Android.mk: Cannot find module with tag '.' 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:
Which means that my library was not built.
I'm using the Android.mk file as in the templates of cocos2d:
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := my-library
LOCAL_C_INCLUDES := /home/me/cocos2d-x-3.4 \
/home/me/cocos2d-x-3.4/extensions \
/home/me/cocos2d-x-3.4/cocos/editor-support
LOCAL_SRC_FILES := main.cpp \
AppDelegate.cpp
LOCAL_LDLIBS := -llog
LOCAL_STATIC_LIBRARIES := cocos2dx_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,.)
The ndk path is set correctly for the project. How can I build my cocos2d-x project correctly when using Eclipse?
The following procedure worked for me:
Goto Eclipse/ADT preferences.
Then C/C++ -> Build -> Envionment
Click on Add.
Put NDK_ROOT in Name and path of NDK under Value.
Now try to
build it from eclipse, if it doesn't work, then Repeat the procedure
and this time put NDK_MODULE_PATH under Name.

Eclipse can't include opencv2 header files

I've created an Android Application Project in Eclipse Juno, and after I've added native support to this project (Android Tools -> Add Native Support). So Eclipse has added in the project automatically a jni directory, within which a .cpp file and the file Android.mk.
Then I've build the project, without errors.
In order to use opencv for android libraries (2.4.5), I've added the path to the 'include' directory of these libraries in the project (Properties -> C/C++ General -> Path And Symbols -> Include Diretories). I've also set in the Eclipse Preferences -> NDK the correct path to the ndk directory in my pc, to make possible to execute ndk-build when I build the projects.
But, if i try to include in the .cpp file:
#include <opencv2/opencv.hpp>
The console show me this result:
12:24:25 **** Build of configuration Default for project ProvaVideoCapture ****
"C:\\Users\\Micaela\\Desktop\\Android\\android-ndk-r8e\\ndk-build.cmd" all
"Compile++ thumb : jniVideoCapture <= jniVideoCapture.cpp
jni/jniVideoCapture.cpp:4:30: fatal error: opencv2/opencv.hpp: No such file or directory
compilation terminated.
make: *** [obj/local/armeabi-v7a/objs/jniVideoCapture/jniVideoCapture.o] Error 1
12:24:26 Build Finished (took 282ms)
My Android.mk file is:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := jniVideoCapture
LOCAL_SRC_FILES := jniVideoCapture.cpp
include $(BUILD_SHARED_LIBRARY)
The Application.mk file that I've added manually (it has not been automatically added by Eclipse) is:
APP_ABI := all
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_PLATFORM := android-9
I don't know how to solve this problem, or what I've done wrong.
Could you help me?
Add path like below to your Android.mk file and check
include E:/OpenCV-2.3.1/share/OpenCV/OpenCV.mk
Sample Android.mk for reference
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_LIB_TYPE:=STATIC
OPENCV_INSTALL_MODULES:=on
include E:/OpenCV-2.3.1/share/OpenCV/OpenCV.mk
include $(OPENCV_MK_PATH)
LOCAL_MODULE := firstcv
LOCAL_SRC_FILES := first.cpp
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_SHARED_LIBRARY)

Categories

Resources