Im trying to use libspotify for an android app but Im having some problems building my c wrapper. Ive created a very small wrapper that only asks libspotify what its version is.
My folder structure looks like this:
jni
|-libs
| |-Android.mk
| |-libspotify.so (symlink)
| |-libspotify.so.12 (symlink)
| |-libspotify.so.12.1.51
|
|-include
| |-libspotify
| |-api.h
|
|-Android.mk
|-spotifywrap.c
/jni/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SHARED_LIBRARIES := libspotify
LOCAL_MODULE := spotifywrap
LOCAL_SRC_FILES := spotifywrap.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
include $(BUILD_SHARED_LIBRARY)
/jni/spotifywrap.c
include <jni.h>
include <libspotify/api.h>
jstring Java_com_example_ndktest_MainActivity_getBuild(JNIEnv * env, jobject this)
{
jstring result = (*env)->NewStringUTF( env, sp_build_id() );
return result;
}
/jni/libs/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libspotify
LOCAL_SRC_FILES := libspotify.so
include $(PREBUILT_SHARED_LIBRARY)
When I run ndk-build I get this:
spotifywrap.c:6: undefined reference to `sp_build_id'
sp_build_id is part of the interface in api.h.
Any ideas on what Im doing wrong?
I have a feeling that your directory structure within the
jnisubdirectory is what’s causing you problems. Try editing yourAndroid.mkbuild file to add this:Also, I have a feeling that you’ll need to copy
libspotify.soto your top-levellibs/armeabidirectory to link successfully.