Search code examples
androidcandroid-ndkjava-native-interfacecygwin

C, Android NDK: import own input.h version containing missing declarations


I'm trying to get the Eventinjector project from pocketmagic.net found here.

This means working with a precoded jni library writen in C. My problem is that I get some build errors when I try to compile the native code. The error log is long and I believe all errors are the same, therefore I'll only post part of it.

    jni/EventInjector.h:718:9: error: (near initialization for 'mt_tool_labels[0].value')
    jni/EventInjector.h:719:9: error: 'MT_TOOL_PEN' undeclared here (not in a function)
    jni/EventInjector.h:719:9: error: initializer element is not constant
    jni/EventInjector.h:719:9: error: (near initialization for 'mt_tool_labels[1].value')
    jni/EventInjector.h:720:9: error: 'MT_TOOL_MAX' undeclared here (not in a function)
    jni/EventInjector.h:720:9: error: initializer element is not constant
    jni/EventInjector.h:720:9: error: (near initialization for 'mt_tool_labels[2].value')
    jni/EventInjector.c: In function 'debug':
    jni/EventInjector.c:82:2: error: format not a string literal and no format arguments [-                        Werror=format-security]
    cc1.exe: some warnings being treated as errors

    make: *** [obj/local/armeabi/objs/EventInjector/EventInjector.o] Error 1

Going throught the comments under the blogpost I discovered that "Alessandro" had the same problem but had found a solution. (post 51) " I had the same issue and imported my own input.h version containing all the missing declarations."

This is the part of the .c file that generates most of the errors:

    static struct label key_labels[] = {
    LABEL(KEY_RESERVED),
    LABEL(KEY_ESC),
    LABEL(KEY_1),
    LABEL(KEY_2),
    LABEL(KEY_3),
    LABEL(KEY_4),
    LABEL(KEY_5),
    LABEL(KEY_6),
    LABEL(KEY_7),
    LABEL(KEY_8),
    LABEL(KEY_9),
    LABEL(KEY_0),
    LABEL(KEY_MINUS),
    LABEL(KEY_EQUAL),
    LABEL(KEY_BACKSPACE),

...

I have no experience in C, and don't know what he means. So my question is: how do I do this?

I have succesfully compiled other JNI libs, using NDK v9 and cygwin, so there should not be a problem with my settings and enviroment.


Solution

  • I had the same issue and imported my own input.h version containing all the missing declarations.

    You can do same thing and replace your input.h (you can search for input.h with those undefine identifiers in linux kernel sources), but easier way is to remove lines containing undefined identifiers from EventInjector.h. Just comment all lines that highlighted red in eclipse, and it should work.