我试图将libspotify用于Android应用程序,但我在构建我的c包装器时遇到了一些问题。我创建了一个非常小的包装器,只询问libspotify它的版本是什么。
我的文件夹结构如下所示:
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)
当我运行ndk-build时,我得到了这个:
spotifywrap.c:6: undefined reference to `sp_build_id'
sp_build_id是api.h中接口的一部分。
关于我做错什么的任何想法?
答案 0 :(得分:1)
我感觉jni
子目录中的目录结构是导致问题的原因。尝试编辑Android.mk
构建文件以添加此内容:
LOCAL_CPPFLAGS = -std=c++0x -D__STDC_INT64__
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
另外,我觉得您需要将libspotify.so
复制到顶级libs/armeabi
目录才能成功链接。