diff --git a/build-daemon.sh b/build-daemon.sh
index 017dcf7572973c8190107388267e8e79ae393bf8..252afd0a03f86066b6fedf863df55d37c052801d 100755
--- a/build-daemon.sh
+++ b/build-daemon.sh
@@ -274,6 +274,7 @@ mkdir -p ${LIBRING_JNI_DIR}
 ${NDK_TOOLCHAIN_PATH}/clang++ --shared -Wall -Wextra  ${ANDROID_APP_DIR}/libringclient/src/main/jni/ring_wrapper.cpp \
                                         ${RING_BUILD_DIR}/src/.libs/libring.a \
                                         -static-libstdc++ \
+                                        -I${RING_SRC_DIR}/contrib/${TARGET_TUPLE}/include \
                                         -I${RING_SRC_DIR}/src -L${RING_SRC_DIR}/contrib/${TARGET_TUPLE}/lib \
                                         ${STRIP_ARG} --std=c++11 \
                                         ${STATIC_LIBS_ALL} \
diff --git a/ring-android/libringclient/src/main/jni/ringservice.c.template b/ring-android/libringclient/src/main/jni/ringservice.c.template
index 61c4e61262926b587fa1db617889f47dfbe3afb0..564f340a73555a37e9471a8cf91c1ef54db487fd 100644
--- a/ring-android/libringclient/src/main/jni/ringservice.c.template
+++ b/ring-android/libringclient/src/main/jni/ringservice.c.template
@@ -1,4 +1,7 @@
 #include "logger.h"
+extern "C" {
+#include "libavcodec/jni.h"
+}
 
 JavaVM *gJavaVM;
 const char *kringservicePath = "cx/ring/daemon/RingserviceJNI";
@@ -18,6 +21,10 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
 
     RING_INFO("JNI_OnLoad");
 
+	if (av_jni_set_java_vm(vm, reserved)) {
+        RING_ERR("JNI_OnLoad: av_jni_set_java_vm failed");
+	}
+
 	//Assume it is c++
 	r = vm->GetEnv ((void **) &env, JNI_VERSION_1_6);
     if (r != JNI_OK) {