PDA

View Full Version : QT to Android serial port API problem?



eddis
22nd December 2011, 11:52
Hello,

Has anyone succeeded to run android serial port with QT using Nessesitas?
At the moment I am trying to learn JNI to reach serial ports here is some example of API:

http://code.google.com/p/android-serialport-api/source/browse/trunk/project/jni/SerialPort.c?r=4

At the moment unsuccessful.. So may be there is some one who made it work and have some example?

eddis
23rd December 2011, 17:52
I faced another problem in way of solving Serial port problem in Android:

In emulator application always crashes at:

JavaVM *m_javaVM;
jint ret;
JNIEnv *env;
ret = m_javaVM->GetEnv((void **) &env, JNI_VERSION_1_6);

Has anyone ever tried to use QT for Android???

qlands
23rd December 2011, 21:00
Hi,

Which version of Nessesitas are you using. Please take a look at this thread http://www.qtcentre.org/threads/41698-QT-in-Android-Example-for-accessing-the-GPS-Service

I that example, I extern the javaVM pointer from qtmain_android.cpp (always included in your application ) to use it with the JNI. I think this is not needed in the new newest versions of neccesitas where you can use the android interface.

Good luck.
Carlos.

eddis
28th December 2011, 08:26
Thank you for replay!
I am using latest version of necessitas: necessitas-0.3
Moreover I am trying to replicate gps project by running my own application and seems unsuccessful.

I have two files SerialPort.c and its H file:
http://code.google.com/p/android-serialport-api/source/browse/trunk/project/jni/SerialPort.c?r=4
http://code.google.com/p/android-serialport-api/source/browse/trunk/android-serialport-api/project/jni/SerialPort.h?spec=svn40&r=40

I simple create necessitas new project with these two files and able to compile only by changing path to jni.h :
#include </home/darka/Archyvas/android-ndk-r7/platforms/android-14/arch-arm/usr/include/jni.h>
Originally there are two include paths in SerialPort.c and SerialPort.h: #include <jni.h>
wich points to:
/usr/lb/jvm/java-1.6.0-openjdk/include/jni.h

In this case errors appears:
../SerialPort.c:-1: error: undefined reference to `__android_log_print'
..
SerialPort.c:-1: error: undefined reference to `__android_log_print'

So it seems that problem is in jni.h file, thus I change it to:

#include </home/darka/Archyvas/android-ndk-r7/platforms/android-14/arch-arm/usr/include/jni.h>

in SerialPort.c and SerialPort.h files.

Then using Target: Android in QT project settings I am able to build it and even run to emulator until initialization of ret = m_javaVM->GetEnv((void **) &env, JNI_VERSION_1_6);
I have associated code with button slot:
JavaVM *m_javaVM;
jint ret;
JNIEnv *env;
ret = m_javaVM->GetEnv((void **) &env, JNI_VERSION_1_6);

So when I press button segmentation fault appears.

Moreover in GPS example file qtmain_android.cpp is:
JNIEnv* env;
if (m_javaVM->AttachCurrentThread((void**)&env, NULL)<0)
{
qCritical()<<"AttachCurrentThread failed";
return false;
}


So I am trying to do similar thing by using: AttachCurrentThread.

using: ret = vm->AttachCurrentThread( (void**)&env, NULL);
Error appears:

../serial_android-build--Necessitas_Qt_4_8_0_for_Android_armv5_Release/../serial_android/mainwindow.cpp:87: error: invalid conversion from 'void**' to 'JNIEnv**'
../serial_android/mainwindow.cpp:87: error: initializing argument 1 of 'jint _JavaVM::AttachCurrentThread(JNIEnv**, void*)'


When I remove (void**) : ret = vm->AttachCurrentThread( &env, NULL);

Application runs but crashes :(

Any help? It seems that wrong jni.h files I include to project..

eddis
4th January 2012, 19:03
It seems that is almost no help here in this forum :(

Moreover, I have some progress. I tried to make simple program using example: http://jgoday.wordpress.com/2009/04/16/jni-with-qt-part1/
to make sure that program is able to run using JNI.

At the moment I am able to compile project and Get simple program run on Desktop by returning JAVA version (see attachment): 7233

But when compiling for Android error appears:
/home/darka/ProgramFiles/QT_work/Android/JNI_1/test_JNI-build--Necessitas_Qt_4_8_0_for_Android_armv7a_Release/../../../../necessitas/Android/Qt/480/armeabi-v7a/src/android/cpp/qtmain_android.cpp:62: error: invalid conversion from 'JNIEnv**' to 'void**'

An error points to file qtmain_android.cpp:62:

JNIEnv* env;
points here-> if (m_javaVM->AttachCurrentThread(&env, NULL)<0)
{
qCritical()<<"AttachCurrentThread failed";
return false;
}


So.. any help?? What am I doing wrong??

ChrisW67
5th January 2012, 00:09
It seems that is almost no help here in this forum
Probably because you are asking questions about accessing specific interfaces from a third-party Qt extension that few here (apparently) have been using. Have you tried asking in the forum (http://groups.google.com/group/android-qt) and wiki (http://sourceforge.net/p/necessitas/wiki/Home/) dedicated to Necessitas?