Build android shared lib using ndk-build without h

2020-06-27 12:49发布

I am able to build a android shared library using ndk-build only when all my src are in the jni foler, but, I would like to build a shared library using ndk-build without need jni folder, because my project doesn't have java code, so how could I do that?

my simple Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := ctest
LOCAL_SRC_FILES := main.cpp
# for logging
LOCAL_LDLIBS    += -llog
# for native asset manager
LOCAL_LDLIBS    += -landroid

include $(BUILD_SHARED_LIBRARY)

2条回答
Luminary・发光体
2楼-- · 2020-06-27 13:07

I would still recommend using a subdirectory like jni for storing the source, to keep the build products in subdirectories such as obj, libs and bin more clearly separated.

But if you have your Android.mk elsewhere, you should be able to do ndk-build APP_BUILD_SCRIPT=path/to/Android.mk. If you don't want to type this every time, you can add a file named jni/Application.mk where you type APP_BUILD_SCRIPT=path/to/Android.mk. Alternatively you have a file named jni/Android.mk which then includes the real Android.mk from where you store it.

查看更多
叛逆
3楼-- · 2020-06-27 13:11

worked as follows:

ndk-build APP_BUILD_SCRIPT=path/to/path/to/project/Android.mk NDK_PROJECT_PATH=path/to/path/to/project
查看更多
登录 后发表回答