Do not see Java class. Why?
Solved
Mobile and Embedded
-
Hello all!
I am developing very simple application. Default from Qt Quick template within simple Java class:
package package.test.usingjava_v1; public class MyJavaClass { public static int mTest(int inNumber) { return inNumber; } }
in *.pro file
android { QT += androidextras ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android OTHER_FILES += \ android/MyJavaClass.java }
in *.cpp
QAndroidJniEnvironment* oJNIEnvironment = new QAndroidJniEnvironment(); jclass oMyJavaClass = oJNIEnvironment->findClass("package/test/usingjava_v1/MyJavaClass"); if(oMyJavaClass == NULL) { qDebug() << "MyJavaClass class not found"; }
When trying to run see this error:
W System.err: java.lang.ClassNotFoundException: Didn't find class "package.test.usingjava_v1.MyJavaClass" on path: DexPathList[[zip file "/data/app/~~EJrl74Lo2NDhB_byCekDiw==/org.qtproject.example.UsingJava_v1-R50S85TnRsBibrRodxNU0A==/base.apk"],nativeLibraryDirectories=[/data/app/~~EJrl74Lo2NDhB_byCekDiw==/org.qtproject.example.UsingJava_v1-R50S85TnRsBibrRodxNU0A==/lib/x86, /data/app/~~EJrl74Lo2NDhB_byCekDiw==/org.qtproject.example.UsingJava_v1-R50S85TnRsBibrRodxNU0A==/base.apk!/lib/x86, /system/lib, /system_ext/lib]] W System.err: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207) W System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:379) W System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:312) W System.err: at org.qtproject.qt5.android.QtNative.startQtApplication(Native Method) W System.err: at org.qtproject.qt5.android.QtNative$7.run(QtNative.java:620) W System.err: at org.qtproject.qt5.android.QtThread$1.run(QtThread.java:61) W System.err: at java.lang.Thread.run(Thread.java:923) W System.err: java.lang.ClassNotFoundException: Didn't find class "package.test.usingjava_v1.MyJavaClass" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib, /system_ext/lib]] W System.err: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207) W System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:379) W System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:312) W System.err: at org.qtproject.qt5.android.QtNative.startQtApplication(Native Method) W System.err: at org.qtproject.qt5.android.QtNative$7.run(QtNative.java:620) W System.err: at org.qtproject.qt5.android.QtThread$1.run(QtThread.java:61) W System.err: at java.lang.Thread.run(Thread.java:923)
Why is that? What am I missing?
-
@bogong
where exactly did you put the java file inside the "$$PWD/android" directory? -
@raven-worx Solution found there was troubles with class location. It wasn't in ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android/src. Forgotten about src. The example published here https://github.com/ArboreusSystems/arboreus_examples/tree/master/qt/UsingJava