Android makefile call import path variable value - android

In an android makefile I have a following line
$(call import-add-path,/Users/bruno/Dev/cocos2d-x-2.1.5)
Now, I am working with several people and having that line is not very people-friendly. I have tried defining that path in an environment variable but it gets ignored when I add it to the call import-add-path line. I output the variable as a warning and the makefile obviously has the vatiable present:
$(warning $(NMP)) # outputs: jni/Android.mk:29: /Users/bruno/Dev/cocos2d-x-2.1.5
$(call import-add-path,$(NMP))
How can I make this work so that is multiple developers friendly?
Edit: Eclipse on OSX, building a cocos2d-x 2.1.5 TestCpp project, android NDK r10c. The error message I get is actually about the missing ABI and asking me if I have set the NDK_MODULE_PATH variable properly and it happens only on a debug build (perhaps GDB makes a difference?).

In the end this setup worked for me:
LOCAL_PATH := $(call my-dir) # ./Project/proj.android/jni/ folder
...
IMPORT_PATH := $(LOCAL_PATH)/../../.. # ./ this gets me to where the modules are located
$(call import-add-path, $(IMPORT_PATH))
$(call import-add-path, $(IMPORT_PATH)/cocos2dx/platform/third_party/android/prebuilt)
$(call import-module,cocos2dx) # ./cocos2dx
$(call import-module, ... etc.
I could not pass environment variables through Eclipse to the ndk-build, but it worked if I called import-add-path with a value relative to $(call my-dir). This should work with multiple developers as well.

Related

Android.mk PREBUILT_SHARED_LIBRARY how to generate LOCAL_SRC_FILES file from script?

I have an NDK project where I build the shared libraries using the cross-compiler and standard gnu make utils. That is done with a separate script. But for the purpose of using the libraries in my project, I would like my Android.mk process to call my script to generate the shared library if it hasn't already been built, and then have Android.mk wrap it using the PREBUILT_SHARED_LIBRARY process.
Currently, if I run my script offline to generate libmy_so.so, then the following makefile will work. However, if I don't run the script explicitly first, I get the following error:
Android NDK: ERROR:/path_to_project/Android.mk:my_module: LOCAL_SRC_FILES points to a missing file
and my script is never called, so the make process is failing before even trying to resolve the dependency.
include $(CLEAR_VARS)
LOCAL_MODULE := my_module
LOCAL_SRC_FILES := libmy_so.so
LOCAL_EXPORT_CFLAGS := # some stuff
LOCAL_EXPORT_LDLIBS := # some stuff
$(LOCAL_PATH)/libmy_so.so:
echo "generate file"
$(shell run_script_that_creates_libmy_so.so)
include $(PREBUILT_SHARED_LIBRARY)
Is there a clean solution to this? I am even ok with running the script automatically as a preprocessing step (I can always have my script quietly exit if the file exists already), but I have not found an incantation that allows the LOCAL_SRC_FILES variable to point to a non-existent file. I have considered placing a dummy libmy_so.so to start, but that is an ugly hack.
Found a hack -- better way?
I found a hack. The makefile prebuilt-library.mk in the NDK contains the following lines:
ifndef prebuilt
$(call __ndk_info,ERROR:$(LOCAL_MAKEFILE):$(LOCAL_MODULE): LOCAL_SRC_FILES points to a missing file)
$(call __ndk_info,Check that $(prebuilt_path) exists, or that its path is correct)
$(call __ndk_error,Aborting)
#endif
I created a copy of this file (and prebuilt-shared-library.mk to which I reference my copy of prebuilt-library.mk) and commented those lines out to stop the error. Then the trick is to make some target that is evaluated first depend on the file I want to generate. After digging through the .mk scripts in the NDK, I found that libraries serves the purpose. By adding libraries: $(LOCAL_PATH)/libmy_so.so to Android.mk, it will finally do what I want.
include $(CLEAR_VARS)
LOCAL_MODULE := my_module
LOCAL_SRC_FILES := libmy_so.so
LOCAL_EXPORT_CFLAGS := # some stuff
LOCAL_EXPORT_LDLIBS := # some stuff
$(LOCAL_PATH)/libmy_so.so:
echo "generate file"
$(shell run_script_that_creates_libmy_so.so)
libraries: $(LOCAL_PATH)/libmy_so.so
include /path/to/my/mk/files/prebuilt-shared-library.mk
This is obviously less than ideal as I would like to make sure my makefiles mature with newer versions of the NDK, but it does the trick. Still interested in more elegant solutions.

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.

target pattern contains no '%'

I tried to build the ndk and get error
/android-ndk-r9/build/core/prebuilt-library.mk:68: *** target pattern contains no '%'. Stop.****
my Android.mk code is :
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_CAMERA_MODULES := on
OPENCV_INSTALL_MODULES := on
#OPENCV_LIB_TYPE:=SHARED
include D:/Books/Java/winx86_01Jan12/OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk
LOCAL_SRC_FILES := F_jni.cpp
LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_LDLIBS += -llog -ldl
LOCAL_MODULE := f
include $(BUILD_SHARED_LIBRARY)
please help Until I resolve my problem.I'm really confused.I tried several ways and I could not solve my issue.
ndk-build invokes make which does not handle the : character in targets well. If your project resides on disk D:, too, then you can refer to OpenCV without the drive letter,
include /Books/Java/winx86_01Jan12/OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk
Otherwise you can try
include //D/Books/Java/winx86_01Jan12/OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk
include //localhost/D$/Books/Java/winx86_01Jan12/OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk
If nothing helps, copy your OpenCV SDK such that you can use a relative path, e.g.
include ../../OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk
PS The source of your troubles is probably cygwin somewhere on the PATH. Since November 2011, NDK r7, ndk-build does not need cygwin. OpenCV made the reciprocate step short afterwards. Unfortunately, many developers still need cygwin for their daily work; furthermore, until recently, you still needed cygwin to run ndk-dgb (you have ndk-gdb-py.cmd now!). So my advice is to remove cygwin\bin directory from your PATH before you run ndk-build.cmd. You can easily do it in Project build properties if you use Ecliplse/ADT to build your native code.

Android NDK, No rule to make target

I've seen this question other places, but the answers don't seem to apply to my situation. I've got a .cpp file (not a .c file). I'm getting the error:
make: * No rule to make target jni/native.c', needed byobj/local/armeabi/objs/native/native.o'. Stop. Cirapi_android C/C++ Problem
Here's my Android.mk file (very simple):
LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_LDLIBS:=-llog
LOCAL_MODULE:=native
LOCAL_SRC_FILES:=native.cpp
include $(BUILD_SHARED_LIBRARY)
I've removed all the extra spaces that solved other's problems. It's complaining about native.c which I don't even have listed in my makefile. Any ideas?
I'm on MacOSX Snow Leopard, Eclipse Juno, NDK r8
Got it to work...not sure what the key was...changed the makefile to..
TOP_LOCAL_PATH:=$(call my-dir)
include $(call all-subdir-makefiles)
LOCAL_PATH := $(TOP_LOCAL_PATH)
include $(CLEAR_VARS)
LOCAL_LDLIBS:=-llog
LOCAL_MODULE:=native
LOCAL_SRC_FILES:=native.cpp
include $(BUILD_SHARED_LIBRARY)
...also removed the .o files from the obj directory...suspected that a clean was not working correctly.

How to specify directory for NDK_MODULE_PATH

I am having a trouble with this simple task for last couple of hours.
I have ndk-modules directory in root of my Android project and I have following in my Android.mk of jni folder
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
NDK_MODULE_PATH := $(LOCAL_PATH)/../ndk-modules
...
$(call import-module,mymodule)
When I build the mk file, I got
Android NDK: /MyApp/jni/Android.mk: Cannot find module with tag 'mymodule' in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?
What am I doing wrong here? How can I specify the path correctly?
UPDATE:
The specification was right. I had a problem in mymodule directory. Sorry for the confusion.
NDK_MODULE_PATH must be in your path. I wanted to specify it in my Android.mk file so I added this line before the import-module line:
$(call import-add-path,my_relative_path)
In my case, I fixed it by realizing NDK searches for:
$NDK_MODULE_PATH/module_name/Android.mk
But my "module_name" is an Eclipse project where Android.mk is under:
$NDK_MODULE_PATH/module_name/jni/Android.mk
So NDK cannot find it. I fixed it by:
Move module_name/jni/* to "somewhere/module_name".
In Android.mk:
$(call import-add-path, /path/to/somewhere)
$(call import-module,module_name)
$(call import-module,mymodule) will search $NDK_MODULE_PATH/mymodule, you may set path to top level of the project or create a folder named mymodule under ndk-modules

Categories

Resources