Reputation: 2051
I am using Android NDK to compile a shared library. I am using the latest build of Android Studio (Android Studio 15- #AI-141.2422023 ). In my cpp code, I am using a thirdparty shared library. When writing the Android.mk file, I have first created a PREBUILT_SHARED_LIBRARY with the following code.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := essentia
LOCAL_SRC_FILES := $(LOCAL_PATH)/../../../essentia-shared/lib/libessentia.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../essentia-shared/include/essentia
include $(PREBUILT_SHARED_LIBRARY)
The problem I am facing is that $(LOCAL_PATH)
is behaving a bit weirdly. The path it is returning is
jni/jni/../../../essentia-shared/lib/libessentia.so
I have the following questions:
jni's
appended at the front of the path. Also when I tried to print the value of LOCAL_PATH
by using $(warning $(LOCAL_PATH))
, it prints jni
.$(LOCAL_PATH)
return the absolute path? This is even more confusing because at times I got the absolute path using $(LOCAL_PATH)
.PS: I am using the terminal internal to Android Studio to run ndk-build
Edit 1: I run the ndk-build
from src/main
Upvotes: 0
Views: 2325
Reputation: 57163
$(call my-dir)
from src/main
for src/main/jni/Android.mk results in "jni"
. On the other hand, LOCAL_SRC_FILES
are always treated relative to the LOCAL_PATH
, which is "jni"
. That's how jni/jni
appears for your .so.
On the other hand, all …_INCLUDES
are treated relative to working directory, which in your case is src/main
from where you launched ndk-build. Due to the delicate nature of current directory, it is a good practice to use absolute paths for all include paths.
So, this is the suggested rewrite of this part of your Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := app-lib
LOCAL_SRC_FILES := a.cpp b.cpp
LOCAL_SHARED_LIBRARIES := essentia
include $(BUILD_SHARED_LIBRARY)
LOCAL_PATH += /../../../essentia-shared
include $(CLEAR_VARS)
LOCAL_MODULE := essentia
LOCAL_SRC_FILES := lib/libessentia.so
LOCAL_EXPORT_C_INCLUDES := $(abspath $(LOCAL_PATH)/include/essentia)
include $(PREBUILT_SHARED_LIBRARY)
Upvotes: 2