1

I want my native executable to be auto-populated to /data/data/.../lib/. For this it is to be named like lib*.so. But if I try to set this name, Android NDK complains:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := libhello.so
LOCAL_SRC_FILES := hello.c
include $(BUILD_EXECUTABLE)
Android NDK: jni/Android.mk:hello.so: LOCAL_MODULE_FILENAME must not contain a file extension
Community
  • 1
  • 1
Vi.
  • 37,014
  • 18
  • 93
  • 148
  • possible duplicate: *[How to package native commandline application in apk?](http://stackoverflow.com/questions/17383552/how-to-package-native-commandline-application-in-apk)* – Alex Cohn Feb 02 '17 at 10:16

2 Answers2

2

A workaround: install with a name Android NDK wants, then rename after installation:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := hello
LOCAL_SRC_FILES := hello.c
include $(BUILD_EXECUTABLE)

all:
        mv ${NDK_APP_DST_DIR}/hello ${NDK_APP_DST_DIR}/libhello.so

And your application can call the executable /data/data/<package>/lib/libhello.so without any preparatory steps.

Vi.
  • 37,014
  • 18
  • 93
  • 148
  • This isn't a good practice. Somewhere else, there may be a different set of rules for `all`. Most likely not, because a convention is not to add rules to `all`. But still, the convention is there not to be broken unless necessary. – Alex Cohn Feb 02 '17 at 20:24
  • Furthermore, it is wrong to expect any `ndk-build` invocation to build `all` explicitly or implicitly. The correct approach is to add `libhello.so` to built modules list, and make sure it depends on `hello`, produced by `$(BUILD_EXECUTABLE)`. – Alex Cohn Feb 02 '17 at 20:28
-1

You are trying to build an executable instead of a shared library. You want to change this:

include $(BUILD_EXECUTABLE)

to this:

include $(BUILD_SHARED_LIBRARY)
Chef Pharaoh
  • 2,387
  • 3
  • 27
  • 38
  • Yes, because of I want an executable that is callable by `java.lang.ProcessBuilder`. – Vi. Sep 29 '16 at 14:36
  • @Vi The shared libraries can be executed (should they have a `main` entry point). I'm using a shared library for a daemon process and it executes. – Chef Pharaoh Sep 29 '16 at 16:16