Search code examples
androidc++android-ndkndk-buildgoogle-vr

libgvr.so linking best practices?


I'm including the libgvr.so library into my Android.mk by including it in my LOCAL_SRC_FILES:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
        GVR_LIB_PATH :=  $(GVR_DIR)/ndk-beta/lib/android_arm
else
        ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
                GVR_LIB_PATH :=  $(GVR_DIR)/ndk-beta/lib/android_arm64
        else
                $(error Invalid architecture!)
        endif
endif
LOCAL_CPPFLAGS := -std=c++11 -Wall -Wextra
LOCAL_SRC_FILES := \
    foo.cpp \
    bar.cpp \
    $(GVR_LIB_PATH)/libgvr.so
LOCAL_C_INCLUDES := \
        include \
    generated \
        $(GVR_DIR)/ndk-beta/include/vr/gvr/capi/include \
        $(GVR_DIR)/ndk-beta/include
LOCAL_ALLOW_UNDEFINED_SYMBOLS := false

The $GVR_LIB_PATH defined at the beginning paths to the correct directories. However, when compiling and linking my code I get unresolvable symbols for functions I am calling here:

Error:(1155) undefined reference to 'gvr_destroy'
Error:(1299) undefined reference to 'gvr_get_time_point_now'
Error:(1248) undefined reference to 'gvr_get_head_pose_in_start_space'

What is the best way to link against libgvr.so using ndk-build? I apologize in advance if this is just a small naming error somewhere I am missing.


Solution

  • I didn't account for different architectures as you're trying, but here's what ended up working for me:

    include $(CLEAR_VARS)
    LOCAL_MODULE := libgvr
    LOCAL_SRC_FILES := $(GVR_ANDROID_BASE)/ndk-beta/lib/android_arm/libgvr.so
    include $(PREBUILT_SHARED_LIBRARY)
    LOCAL_SHARED_LIBRARIES  += libgvr
    

    GVR_ANDROID_BASE points to the directory unpacked from a github clone ZIP archive.