Issue
I am having some issues using the Android NDK (for first time) and compiling a simple C file. The odd thing is that I get these compile errors on the standard header files themselves which I would expect no errors to be generated within these unless I didn't include all of the includes files. Here is what I did...
javac myJavaFile.java
javah -d location/include location.MyJavaFile
This runs fine and creates the appropriate header file. I then run the android ndk C compiler on my associated C file but I get errors in the standard header files. My command is as follows (shortened absolute paths for readability)
...android-ndk-r11c-windows-x86_64\android-ndk-r11c\toolchains\x86_64-4.9\prebuilt\
windows-x86_64\bin\x86_64-linux-android-gcc.exe -I ...jdk1.6.0_35\include -I
...android-ndk-r11c-windows-x86_64\android-ndk-r11c\platforms\android-18\arch-x86\usr\
include -I ...jdk1.6.0_35\include\win32 -c myCFile.c
I get the following generated errors when doing this:
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:621:25: error: expected ')' before '*' token
jcharArray (JNICALL *NewCharArray)
^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:623:26: error: expected ')' before '*' token
jshortArray (JNICALL *NewShortArray)
^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:625:24: error: expected ')' before '*' token
jintArray (JNICALL *NewIntArray)
^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:627:25: error: expected ')' before '*' token
jlongArray (JNICALL *NewLongArray)
^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:629:26: error: expected ')' before '*' token
jfloatArray (JNICALL *NewFloatArray)
^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:631:27: error: expected ')' before '*' token
jdoubleArray (JNICALL *NewDoubleArray)
^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:634:25: error: expected ')' before '*' token
jboolean * (JNICALL *GetBooleanArrayElements)
^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:636:22: error: expected ')' before '*' token
jbyte * (JNICALL *GetByteArrayElements)
^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:638:22: error: expected ')' before '*' token
jchar * (JNICALL *GetCharArrayElements)
^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:640:23: error: expected ')' before '*' token
jshort * (JNICALL *GetShortArrayElements)
^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:642:21: error: expected ')' before '*' token
jint * (JNICALL *GetIntArrayElements)
^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:644:22: error: expected ')' before '*' token
jlong * (JNICALL *GetLongArrayElements)
^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:646:23: error: expected ')' before '*' token
jfloat * (JNICALL *GetFloatArrayElements)
^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:648:24: error: expected ')' before '*' token
jdouble * (JNICALL *GetDoubleArrayElements)
^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:651:19: error: expected ')' before '*' token
void (JNICALL *ReleaseBooleanArrayElements)
^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:653:19: error: expected ')' before '*' token
void (JNICALL *ReleaseByteArrayElements)
^
C:\Program Files\Java\jdk1.6.0_35\include\win32/jni_md.h:11:19: error: expected declaration specifiers before '__declspec'
#define JNIEXPORT __declspec(dllexport)
So what am I doing wrong here? Wrong compiler? Include file, jni.h does exist. I'm running on Windows 7 Pro 64 bit.
Solution
It looks like you're including the Windows JDK version of jni.h. You should be including the version that is shipped with the NDK for your target platform. For instance, if you're targeting Gingerbread on an ARM device, use platforms/android-9/arch/arm/usr/include/jni.h.
But the fact that you're invoking the C compiler directly makes me think you might be in for a rough time. The NDK is sort of a finicky toolchain. The code it emits is intended to be dynamically linked into a Dalvik executable, so it needs to have its gcc options set just right or it won't load. It is not a normal Linux toolchain. There's a (possibly apocryphal) story that for a long time only one person at Google understood the NDK build system, and every NDK release had to be built on his desktop or it wouldn't work. ;-)
I'd advise you to start by using the ndk-build script or the Android Studio gradle plugin, which is currently (April 2016) still labeled "experimental." Once you understand how the toolchain works, then you can switch to a make system more to your liking.
Answered By - Ian Ni-Lewis
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.