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.
Related
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
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.
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.
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)
I am using native code in my android app. Firstly I was only using one library. So everything worked fine. But now I have to integrate one more library into it. I've no idea what should be the ideal structure of the jni folder of my project (as in where to place the entire code, etc.). I found a work around. I created two folders inside jni .i.e library1 and library2. Again created a jni folder inside both the folders and placed respective code in the folders.
I got it to compile. Both .so files are being generated, but I am unable to use it in my application. I cant load the library using System.loadLibrary("library1.so"); Also tried providing full path. But failed
Also I have no idea what to write inside the parent jni folder's Android.mk file.
Current structure:
project_folder -> jni -> library1 -> jni -> "source code" an Android.mk is written here
project_folder -> jni -> library2 -> jni -> "source code" an Android.mk is written here
UPDATE #1 :
Gdbserver : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
make: *** No rule to make target `jni/zap/jni/zap/zap/error.c', needed by `obj/local/armeabi/objs-debug/zap/jni/zap/zap/error.o'. Stop.
I am not using Application.mk.
This is my Android.mk:
TOP_PATH := $(call my-dir)
# Build library 1
include $(CLEAR_VARS)
LOCAL_PATH := $(TOP_PATH)/zap
LOCAL_MODULE := zap
LOCAL_C_INCLUDES := $(LOCAL_PATH)/zap
LOCAL_SRC_FILES := $(LOCAL_PATH)/zap/error.c \
$(LOCAL_PATH)/zap/hello-jni.c \
$(LOCAL_PATH)/zap/zap.c \
$(LOCAL_PATH)/zap/zapd.c \
$(LOCAL_PATH)/zap/zaplib.c
include $(BUILD_SHARED_LIBRARY)
The best structure I've found is to use the jni/ folder for ndk-build makefiles only, and keep the source outside in their own folders. This is easy to add to existing projects without restructuring your tree under jni.
However, you do have to be careful about how you handle the LOCAL_PATH variable and use of $(call my-dir). Here's a working example:
MyProject/
library1/
source1.cpp
library2/
source2.cpp
jni/
Android.mk
Application.mk
Android.mk:
# TOP_PATH refers to the project root dir (MyProject)
TOP_PATH := $(call my-dir)/..
# Build library 1
include $(CLEAR_VARS)
LOCAL_PATH := $(TOP_PATH)/library1
LOCAL_MODULE := library1
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := source1.cpp
include $(BUILD_SHARED_LIBRARY)
# Build library 2
include $(CLEAR_VARS)
LOCAL_PATH := $(TOP_PATH)/library2
LOCAL_MODULE := library2
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := source2.cpp
include $(BUILD_SHARED_LIBRARY)
You can optionally split out the sections in Android.mk to their own makefiles.
I discovered that when compiling from the command line, I can include multiple libraries by running android update project twice, once with each library:
android update project -l ../SDK/library1/ --path . --name $name --target 23 --subprojects
android update project -l ../SDK/library2/ --path . --name $name --target 23 --subprojects
ant release