Search code examples
androidc++android-ndk

Cannot get an OEX program to run on Android


I'm trying to implement an OEX (open engine exchange protocol) chess program for Android. This has been discussed at What is OEX (Open Exchange Protocol?) and can I call such APK from my app? earlier.

The java-part of the program runs fine, yet the native library always segfaults. Even with something simple as

#include <stdio.h>

int main(int argc, char *argv[])
{
        printf("Hello, world!\n");

        return 0;
}

I noticed one thing to be different: the libstockfish.so library seems to be linked to /system/bin/linker while my library is not linked at all?

file libs/x86_64/libstockfish.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /system/bin/linker64, BuildID[sha1]=b690a6bb7630099c6618950a9e1604850f1de836, stripped

file libs/x86_64/libDog.so libs/x86_64/libDog.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=93a9d3635eef9fc0f2140a87956db9ac80459993, stripped

What is it that I could be doing wrong?

I'm using the ndk-build script:

jni/Application.mk:

APP_ABI := all
APP_PLATFORM     := 21
#NDK_TOOLCHAIN_VERSION := 4.9
APP_STL := c++_shared
APP_CPPFLAGS += -frtti
APP_CPPFLAGS += -std=c++17

jni/Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := Dog
LOCAL_SRC_FILES := test.cpp

LOCAL_STRIP_MODE := none

LOCAL_PRELINK_MODULE := false

LOCAL_CPPFLAGS += -std=c++17 -Wall -DVERSION=\"0.8\" -DNAME_EXTRA=\"\" -fexceptions -Wno-c++11-narrowing -fPIC -pie -fPIE
LOCAL_LDLIBS += -shared
LOCAL_LDFLAGS += -fPIC -pie -fPIE -Wl,--entry=main,-dynamic-linker=/system/bin/linker

LOCAL_CPP_FEATURES := exceptions

include $(BUILD_SHARED_LIBRARY)

Any ideas?


Solution

  • Found the solution: apparently the idea is to trick the packaging system by creating a regular binary and renaming it to e.g. libstockfish.so. Then the board-programs can happily import them and play chess with them.