Calling from a pure method c to a Java method

This forum is about all development around libVLC.
gmv
Blank Cone
Blank Cone
Posts: 15
Joined: 18 Feb 2013 18:46

Calling from a pure method c to a Java method

Postby gmv » 11 Jul 2013 00:12

Hi,

I have to call from a pure c method of decoder.c to a method of Java class, and i don't know how initialize the pointers of native code that they are necessary to connect Java and C . In my project, these classes are located so:

in home/virginia/workspace/

vlc
----src
-------input
-------------decoder.c

-------misc
------------picture.c

vlc-android
----src
--------org.videolan.vlc.gui.video
---------------------------------VirtualActivity (java class)
----jni
---------Android.mk



I'm testing with simple methods to comprobe that it works fine. Then in decoder.c, i have got the next lines of code:

In decoder.c:

Code: Select all

msg_Warn( p_dec, "Definición del array"); int i; int size = 129600; for ( i= 0; i< size ;i++){ aux[i] = 2 ; } newFunction(aux) ;
In picture.c:

Code: Select all

void newFunction(int color) { JavaVM* jvm; JNIEnv* env; JavaVMInitArgs args; JavaVMOption options[1]; args.version = JNI_VERSION_1_6; args.nOptions = 1; options[0].optionString = "-Djava.class.path=/home/virginia/workspace/android/vlc-android/src/"; args.options = options; args.ignoreUnrecognized = JNI_FALSE; JNI_CreateJavaVM(&jvm, (void **)&env, &args); jclass cls = (*env)->FindClass(env,"org.videolan.vlc.gui.video.VirtualActivity"); jmethodID mid = (*env)->GetStaticMethodID(env, cls, "arrays", "([I)V"); (*env)->CallVoidMethod(env,cls, mid, color); }
And in VirtualActivity.java:

Code: Select all

public void arrays(int arr[]){ int i; System.out.println("La longitud del array es" + arr.length ); for (i = 0; i < arr.length; i++) { System.out.println("Este mensaje se está imprimiendo desde java" + ", array = " + arr[i] + " para " + " i = " + i ); } }
But when i compile, i get the next error:

Code: Select all

/home/vmg/android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ../vlc/android/src/.libs/libvlccore.a(picture.o): in function newFunction:../../src/misc/picture.c:646: error: undefined reference to 'JNI_CreateJavaVM'
In Android.mk:

Code: Select all

include $(CLEAR_VARS) LOCAL_MODULE := native LOCAL_SRC_FILES := ../../vlc/src/misc/picture.c ARCH=$(ANDROID_ABI) LOCAL_C_INCLUDES := $(VLC_SRC_DIR)/include \ $(VLC_SRC_DIR)/include/vlc \ $(ANDROID_NDK)/platforms/android-9/arch-arm/usr/include \ $(ANDROID_NDK)/platforms/android-9/arch-arm/usr/include/android \ /usr/lib/jvm/java-6-openjdk/include \ /usr/lib/jvm/java-6-openjdk/include/linux \ CPP_STATIC=$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++$(CXXSTL)/libs/$(ARCH)/libgnustl_static.a LOCAL_CFLAGS := -std=gnu99 ifeq ($(ARCH), armeabi) LOCAL_CFLAGS += -DHAVE_ARMEABI # Needed by ARMv6 Thumb1 (the System Control coprocessor/CP15 is mandatory on ARMv6) # On newer ARM architectures we can use Thumb2 LOCAL_ARM_MODE := arm endif ifeq ($(ARCH), armeabi-v7a) LOCAL_CFLAGS += -DHAVE_ARMEABI_V7A endif LOCAL_LDLIBS := -L$(VLC_CONTRIB)/lib \ $(VLC_MODULES) \ $(VLC_BUILD_DIR)/lib/.libs/libvlc.a \ $(VLC_BUILD_DIR)/src/.libs/libvlccore.a \ $(VLC_BUILD_DIR)/compat/.libs/libcompat.a \ [b] -L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server[/b] \ -ldl -lz -lm -llog \ -ldvbpsi -lebml -lmatroska -ltag \ -logg -lFLAC -ltheora \ -lmpeg2 -ldca -la52 \ -lavformat -lavcodec -lswscale -lavutil -lpostproc -lgsm -lopenjpeg \ -lliveMedia -lUsageEnvironment -lBasicUsageEnvironment -lgroupsock \ -lspeex -lspeexdsp \ -lxml2 -lpng -lgnutls -lgcrypt -lgpg-error \ -lfreetype -liconv -lass -lfribidi -lopus \ [code] -ljvm
\
$(CPP_STATIC)
include $(BUILD_SHARED_LIBRARY)[/code]

In the folder /usr/lib/jvm/java-6-openjdk/include is the jni.h file, where is the declaration of :

Code: Select all

#ifdef _JNI_IMPLEMENTATION_ #define _JNI_IMPORT_OR_EXPORT_ JNIEXPORT #else #define _JNI_IMPORT_OR_EXPORT_ JNIIMPORT #endif _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetDefaultJavaVMInitArgs(void *args); _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM **pvm, void **penv, void *args); _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetCreatedJavaVMs(JavaVM **, jsize, jsize *);
What am i doing wrong?

I'm sorry to have many doubts, but i'm beginner.
Thanks so much!

Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 5 guests