I am following the steps on http://developer.android.com/sdk/ndk/overview.html to build the hello-jni sample, however when I get to Step 2 to run
cd $NDK-ROOT/samples/hello-jni
$NDK-ROOT/ndk-build
in the Cygwin command prompt, I receive the following error messages:
/bin/sh: -c: line 0: unexpected EOF while looking for matching `''
/bin/sh: -c: line 1: syntax error: unexpected end of file
Android NDK: Host awk tool is outdated. Please define HOST_AWK to point to Gawk
or Nawk !
I have Cygwin 1.7.9, Gnu Make 3.8.2, and Gawk 3.1.8 on my Windows machine, along with the r5b release of the Android NDK.
I also have set the HOST_AWK environment variable, which points to my Gawk folder.
Unfortunatley the sample cannot run successfully without this step, (if I run hello-jni, I immediately receive an UnsatisfiedLinkError exception).
Below is the portion of the init.mk file on my machine (found in NDK_ROOT/build/core) which creates this error:
# Location of all awk scripts we use
BUILD_AWK := $(NDK_ROOT)/build/awk
AWK_TEST := $(shell $(HOST_AWK) -f $(BUILD_AWK)/check-awk.awk)
$(call ndk_log,Host awk test returned: $(AWK_TEST))
ifneq ($(AWK_TEST),Pass)
$(call __ndk_info,Host awk tool is outdated. Please define HOST_AWK to point to Gawk or Nawk !)
$(call __ndk_error,Aborting.)
endif
Thank-you for your help
Try updating your awk tool. Seems to an an outdated version (perhaps). Also ensure that NDK root is defined to where you have your NDK source and ensure that your awk tool is located in the build directory of your NDK Source.
NDK_ROOT
Try settings this environment variable to where your NDK root is. Whenever this is defined (Typically at the top)
Instead of HOST_AWK=gawk.exe, just do HOST_AWK=gawk
It turns out there was an apostrophe in my HOST_AWK path, which was causing the problem.
reference
https://stackoverflow.com/q/8121153/411522
mine worked fine now.what to do is: just rename the prebuilt awk in ndk
Related
I have multiple static libs that are built using jni. I have a scheme that includes other mk files, etc to allow me to share compile settings, include files from other dependent projects, etc.
I have set it up successfully on the mac and have been building it. However, when I tried to do the same in windows under cygwin I'm running into issues...
Here is my jni/Android.mk file..
LOCAL_PATH := $(call my-dir)
INJ_PROJECT_PATH := $(PWD)
include $(INJ_PROJECT_PATH)/jni/Project.mk
The problem I'm seeing is that ndk-build is complaining about the Project.mk file. Here is what I'm seeing..
shammi#SHAMMIDEV /cygdrive/c/projects/injitiProjects/injitiEngine/Engine/Core
$ ndk-build.cmd NDK_APP_OUT=../../build/Android/Engine/release
jni/Android.mk:5: /cygdrive/c/projects/injitiProjects/injitiEngine/Engine/Core/jni/Project.mk: No such file or directory
jni/Android.mk:5: /cygdrive/c/projects/injitiProjects/injitiEngine/Engine/Core/jni/Project.mk: No such file or directory
jni/Android.mk:5: /cygdrive/c/projects/injitiProjects/injitiEngine/Engine/Core/jni/Project.mk: No such file or directory
jni/Android.mk:5: /cygdrive/c/projects/injitiProjects/injitiEngine/Engine/Core/jni/Project.mk: No such file or directory
C:/projects/Android/sdk/ndk-bundle/build//../build/core/build-all.mk:89: Android NDK: WARNING: There are no modules to build in this project!
make: *** No rule to make target `/cygdrive/c/projects/injitiProjects/injitiEngine/Engine/Core/jni/Project.mk'. Stop.
I have confirmed that /cygdrive/c/projects/injitiProjects/injitiEngine/Engine/Core/jni/Project.mk does exist, and I am the owner and it has read permissions for user/group/other.
Again, this exact same setup works absolutely fine on the mac. I'm just looking at having a portable dev environment.
What am I missing here..?
I guess I forgot that ndk-build.cmd was a windows shell batch script (DOH).
The answer was that I was able to call /build/ndk-build which is a sh script that is comfortable running in cygwin.
You probably need to use LOCAL_PATH instead of PWD. I'm not really sure how PWD gets set (I think it's a make builtin?), but we actually have control over LOCAL_PATH and can make sure it gets set in the right way for cygwin.
Instead of include what if you define it to be APP_BUILD_SCRIPT?
for ex.
APP_BUILD_SCRIPT := jni/Android.mk
Also Id try $(shell $pwd) instead of $(PWD) if the above doesn't work, usually ndk doesn't interpret shell commands for me if I don't use the shell in the parenthesis.
I've spent a day on this and can't seem to configure my dev environment for a NDK toolchain that will support standard C++ libraries. The story is I'm trying to cross compile libnfnetlink and libnetfilter_queue for ARM (Android).
First I'm using the following:
Nexus 5 with CyanogenMod 11 (I forget, doesn't matter I'm not even on the device yet)
Ubuntu 12.04 32-bit
Android SDK bundle: adt-bundle-linux-x86-20140702
Android NDK: android-ndk-r10c
There is a great blog on doing this here but its incomplete as Netfilter uses stlc++ and there's no word on a NDK install/setup that would work with simply calling ndk-build. Just copying the files into /jni and calling ndk-build won't work alone.
Anyways, my specific problem is when I straight copy the Netfilter lib source structure into an empty Project's /jni directory, I get this:
user#ubuntu:~/Projects/NetfilterTest/NetfilterNativeTest/jni$ ndk-build
[armeabi] Compile thumb : netfilter_queue <= libnetfilter_queue.c
In file included from /home/user/Projects/NetfilterTest/NetfilterNativeTest/jni/libnetfilter_queue/src/libnetfilter_queue.c:35:0:
/home/user/Projects/NetfilterTest/NetfilterNativeTest/jni/libnetfilter_queue/src/internal.h:4:20: fatal error: config.h: No such file or directory
compilation terminated.
make: *** [/home/user/Projects/NetfilterTest/NetfilterNativeTest/obj/local/armeabi/objs/netfilter_queue/libnetfilter_queue/src/libnetfilter_queue.o] Error 1
The config.h file can't be found. After some googling I realize its because the standard C++ libraries aren't available in the prebuilt tool chains.
Everything points to me creating my own tool chain. So I build my own cross compiler using the scripts that the NDK includes.
cd /home/user/android-ndk-r10c/build/tools
./make-standalone-toolchain.sh --platform=android-19 --ndk-dir=/home/user/android-ndk-r10c/ --install-dir=/home/user/android-ndk-r10c/prebuilt/android-arm/android-19
To confirm that config.h is included in my tool chain I searched for it. It's there:
user#ubuntu:~/Projects/NetfilterTest/NetfilterNativeTest/jni$ find /home/user/android-ndk-r10c/prebuilt/android-arm/android-19/ -iname config.h
/home/user/android-ndk-r10c/prebuilt/android-arm/android-19/sysroot/usr/include/linux/config.h
Naturally I need to setup my environment and the Android.mk
JAVA_HOME=/usr/local/java/jdk1.6.0_45
JRE_HOME=$JAVA_HOME/jre
ANDROID_SDK=/home/user/adt-bundle-linux-x86-20140702
ANDROID_NDK=/home/user/android-ndk-r10c
ANDROID_CHAIN=/home/user/android-ndk-r10c/prebuilt/android-arm/android-19
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$ANDROID_SDK/sdk/platform-tools:$ANDROID_SDK/sdk/tools:$ANDROID_NDK:$ANDROID_CHAIN/bin
SYSROOT=$ANDROID_NDK/platforms/android-19/arch-arm
CC=arm-linux-androideabi-gcc
export CC
export ANDROID_SDK
export ANDROID_NDK
export SYSROOT
export JAVA_HOME
export JRE_HOME
export PATH
Here's my Android.mk (based on Roman10's blog:
LOCAL_PATH:=$(call my-dir)
#####################################################################
# build libnflink #
#####################################################################
include $(CLEAR_VARS)
LOCAL_MODULE:=nflink
LOCAL_C_INCLUDES:= $(LOCAL_PATH)/libnfnetlink/include
LOCAL_SRC_FILES:=\
libnfnetlink/src/iftable.c \
libnfnetlink/src/rtnl.c \
libnfnetlink/src/libnfnetlink.c
include $(BUILD_STATIC_LIBRARY)
#####################################################################
# build libnetfilter_queue #
#####################################################################
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/libnfnetlink/include \
$(LOCAL_PATH)/libnetfilter_queue/include
LOCAL_MODULE:=netfilter_queue
LOCAL_SRC_FILES:=libnetfilter_queue/src/libnetfilter_queue.c
LOCAL_STATIC_LIBRARIES:=libnflink
include $(BUILD_STATIC_LIBRARY)
#####################################################################
# build our code #
#####################################################################
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/libnfnetlink/include \
$(LOCAL_PATH)/libnetfilter_queue/include
LOCAL_MODULE:=nfqnltest
#LOCAL_LDLIBS:=-lstdc++
LOCAL_SRC_FILES:=nfqnl_test.c
LOCAL_STATIC_LIBRARIES:=libnetfilter_queue
LOCAL_LDLIBS:=-llog -lm
include $(BUILD_EXECUTABLE)
I still get config.h not found using ndk-build.
I've read that the ndk-build command leverages a config.mk/setup.mk that Google includes in the NDK and has to be modified to point to an alternative toolchain.
I'm completely floored that Google's own tools can't simply point to a custom toolchain that they give you scripts to create. If anyone has any suggestions on how I can use my toolchain to compile Netfilter or just in general it would be a great help.
Thanks in advance!
I can't find any reference to either internal.h or config.h when I search for a version of libnetfilter_queue.c on the web, so I'm not sure what version of the file you're using - can you point to which one you have?
Also, the config.h it looks for isn't the one you found in your toolchain (which should be included as linux/config.h) but most probably is one that you're expected to generate by running a configure script. So unless you've run the configure script (or have a pregenerated config.h from elsewhere) you can't really build it.
Finally, nothing of this has anything to do with libstdc++ since all your source files seem to be pure C, not C++.
In my jni directory, I run the following command:
$ ./libvpx/configure --target=armv7-android-gcc --disable-examples --sdk-path=/home/peter/adt/android-ndk-r9/
This results in generating Android.mk in libvpx/build/make directory
Next, I create Android.mk in jni directory:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include libvpx/build/make/Android.mk
When I run ndk-build, it ends up creating libvpx.so.
However, I would really like to create a static library.
I started all over and ran the configuration with an extra flag:
$ ./libvpx/configure --target=armv7-android-gcc --disable-examples --sdk-path=/home/peter/adt/android-ndk-r9/ --enable-static
However, running ndk-build still results in creating libvpx.so.
Does any know how I can configure libvpx to create a static library? Thank you in advance for your help.
I was able to successfully build an arm static library, though I have not yet integrated it with an Android application as I am building libvpx as a component for another native library.
Note that in my case the Android.mk already existed in the directory tree and was unaffected by the configure script, which is apparently contrary to your experience. To build the static library I simply invoked configure and then make:
$ make clean
$ ./configure --target=armv7-android-gcc --disable-examples --sdk-path=/home/me/android-ndk-r9b/
$ make
In my case I had to do a clean build because I had some cruft left from an earlier build attempt that would break the build otherwise.
The result is libvpx.a and libvpx_g.a.
I'm building an android application in eclipse. I need to call a function written in C/C++.
I setup everything including NDK, cygwin, etc (ask if u need more details), but when I try to run the project, I get this error
**** Build of configuration Default for project C_Google_FaceDetect ****
C:\cygwin\bin\bash.exe C:\Android_NDK\ndk-build
cygwin warning:
MS-DOS style path detected:
C:\Documents and Settings\John Smith\eclipse_workspace\C_Google_FaceDetect
Preferred POSIX equivalent is:
/cygdrive/c/Documents and Settings/John Smith/eclipse_workspace/C_Google_FaceDetect
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
C:\Android_NDK\ndk-build: line 40: dirname: command not found
C:\Android_NDK\ndk-build: line 78: uname: command not found ERROR:
Unknown host operating system:
*** Build Finished ****
The project name is C_Google_FaceDetect
If I use cygwin to get the PATH, I get
John Smith#E-USK3631BE /cygdrive/c
$ echo $PATH
/cygdrive/c/Program Files/PC Connectivity Solution
/cygdrive/c/WINDOWS/system32
/cygdrive/c/WINDOWS
/cygdrive/c/WINDOWS/System32/Wbem
/cygdrive/c/WINDOWS/system32/nls
/cygdrive/c/WINDOWS/system32/nls/ENGLISH
/cygdrive/c/Program Files/IVI Foundation/IVI/bin
/cygdrive/c/Program Files/IVI Foundation/VISA/WinNT/Bin
/cygdrive/c/Program Files/IVI Foundation/VISA/WinNT/Bin
/cygdrive/c/Program Files/MATLAB/R2012a/runtime/win32
/cygdrive/c/Program Files/MATLAB/R2012a/bin
/cygdrive/c/Program Files/MATLAB/R2010a/runtime/win32
/cygdrive/c/Program Files/MATLAB/R2010a/bin
/cygdrive/c/Program Files/emgucv 2.1.0.793/bin
/cygdrive/c/Documents and Settings/mchi7jb2/My Documents/GLUT/lib
/cygdrive/c/OGLSDK/lib
/cygdrive/c/Program Files/Microsoft Platform SDK for Windows Server 2003 R2/Lib
/cygdrive/c/Program Files/MATLAB/MATLAB Compiler Runtime/v713/runtime/win32
/cygdrive/c/Python27/python.exe
/cygdrive/c/Program Files/QuickTime/QTSystem
/cygdrive/c/Android_NDK
/cygdrive/c/Android_NDK/build
/cygdrive/c/Program Files/Java/jdk1.7.0_04/bin
/cygdrive/c/Android_NDK
/cygdrive/c/Android_NDK/ndk-build/usr/bin
/cygdrive/c/Android_SDK/tools
/cygdrive/c/Android_SDK/platform-tools
/cygdrive/c/Android_NDK
My Android.mk file is as follows
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := C_Google_FaceDetect
LOCAL_SRC_FILES := yuv_decoder.c
include $(BUILD_SHARED_LIBRARY)
Please help
The problem is gonne when I used this
C:\cygwin\bin\bash.exe --login -i C:\Android_NDK\ndk-build
instead of this
C:\cygwin\bin\bash.exe C:\Android_NDK\ndk-build
in the eclipse build command
I found the answer there,Running Cygwin commands from batch file
maybe the problem is only gonne because I have bigger problems now I dunno
I am getting "Android NDK: Host 'awk' tool is outdated. Please define HOST_AWK to point to Gawk or Nawk !" error on latest android ndk revision 7.
Solved the problem.
Solution:
Navigate to ../android-ndk-r7/prebuilt/linux-x86/bin
Rename the file awk to awk_
Imoprtant thing to note on windows machine:
ndk revision 7 onwards, ndk source can be built without cygwin, ie..,
instead of calling ndk-build command from inside a Cygwin shell, you should call run ndk-build.cmd inside a MSDOS command window.
It works because probably ndk-build first tries to use a locally defined, but old (at least for Linux), version of awk. By renaming it, we make it unreachable by such command, so, apparently, ndk-build calls the system-wide awk.
This Solution (from Santhosh) works also under windows:
Navigate to ../android-ndk-r7/prebuilt/windows/bin Rename the file
rename awk.exe to awk_.exe
I think the problem is $(HOST_AWK) not defined correctly and local prebuild awk.exe doesn't work. Thus prebuild awk.exe should be deleted or renamed and use gawk if awk is not defined.
To solve this problem:
1 - Rename <drive>\android-ndk\prebuilt\windows\bin\awk.exe to <drive>\android-ndk\prebuilt\windows\bin\awk_.exe.
2 - Open <drive>\android-ndk\build\core\init.mk
Replace
HOST_AWK := $(strip $(HOST_AWK))
ifndef HOST_AWK
HOST_AWK := awk
endif
with
HOST_AWK := $(strip $(HOST_AWK))
ifndef HOST_AWK
HOST_AWK := gawk
endif
Note that awk renamed to gawk.
Take a look at this japanese post: http://d.hatena.ne.jp/yohpapa/20111113/1321198570
They explain how to solve your problem. Is in japanese, but the commands are legible =)
Hope this helps...
I was having a problem with different versions of awk on windows. This change uses the cygwin version of awk from a cygwin console and the prebuilt version from a dos console.
Add to init.mk:
ifeq ($(HOST_OS),cygwin)
HOST_AWK := /bin/awk
endif