我爲Android使用Qt 5.7。我嘗試編譯Andorid的基本應用程序,但我看到Unfortunately app has stopped
和應用程序關閉。
AndroidClass.java:適用於Android的Qt:Jni - 不幸的應用程序已停止
package com.test;
public class AndroidClass
{
public static void work()
{
System.out.println("Java Code worked!");
}
}
android.h:
#ifndef ANDROID_H
#define ANDROID_H
#include <QObject>
#include <QAndroidJniObject>
#include <QDebug>
#include <jni.h>
class Android : public QObject
{
Q_OBJECT
public:
explicit Android(QObject *parent = 0);
Q_INVOKABLE void work() const;
signals:
public slots:
};
#endif // ANDROID_H
android.cpp:
#include "android.h"
Android::Android(QObject *parent) : QObject(parent)
{
}
void Android::work() const
{
/*****************This is work!************************************
QAndroidJniObject::callStaticMethod<void>("com/test/AndroidClass",
"work", "()V");
*****************************************************************/
// This part is not working:
JNIEnv* env;
jclass class_ = env->FindClass("com/test/AndroidClass");
if (!class_)
{
qDebug() << "Class Not Found!\n";
}
jmethodID method_id = env->GetStaticMethodID(class_, "work", "()V");
if (!method_id)
{
qDebug() << "Method ID Error!\n";
}
env->CallStaticVoidMethod(class_, method_id);
}
.pro文件包括:
android: {
QT += androidextras
INCLUDEPATH += /home/username/Android/Sdk/ndk-bundle/platforms/android-19/arch-arm/usr/include/
INCLUDEPATH += /home/username/Android/Sdk/ndk-bundle/platforms/android-19/arch-arm/usr/include/android
}
我的控制檯輸出:
W/System.err(10313): java.lang.ClassNotFoundException: android.graphics.drawable.RippleDrawable
W/System.err(10313): at java.lang.Class.classForName(Native Method)
W/System.err(10313): at java.lang.Class.forName(Class.java:251)
W/System.err(10313): at java.lang.Class.forName(Class.java:216)
W/System.err(10313): at org.qtproject.qt5.android.ExtractStyle.getClass(ExtractStyle.java:395)
W/System.err(10313): at org.qtproject.qt5.android.ExtractStyle.<init>(ExtractStyle.java:98)
W/System.err(10313): at org.qtproject.qt5.android.QtActivityDelegate.loadApplication(QtActivityDelegate.java:512)
W/System.err(10313): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(10313): at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err(10313): at org.qtproject.qt5.android.bindings.QtLoader.loadApplication(QtLoader.java:237)
W/System.err(10313): at org.qtproject.qt5.android.bindings.QtLoader.startApp(QtLoader.java:647)
W/System.err(10313): at org.qtproject.qt5.android.bindings.QtActivityLoader.onCreate(QtActivityLoader.java:181)
W/System.err(10313): at org.qtproject.qt5.android.bindings.QtActivity.onCreate(QtActivity.java:269)
W/System.err(10313): at android.app.Activity.performCreate(Activity.java:5447)
W/System.err(10313): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
W/System.err(10313): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
W/System.err(10313): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
W/System.err(10313): at android.app.ActivityThread.access$800(ActivityThread.java:166)
W/System.err(10313): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
W/System.err(10313): at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err(10313): at android.os.Looper.loop(Looper.java:136)
W/System.err(10313): at android.app.ActivityThread.main(ActivityThread.java:5584)
W/System.err(10313): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(10313): at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err(10313): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
W/System.err(10313): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
W/System.err(10313): at dalvik.system.NativeStart.main(Native Method)
W/System.err(10313): Caused by: java.lang.NoClassDefFoundError: android/graphics/drawable/RippleDrawable
W/System.err(10313): ... 26 more
W/System.err(10313): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.graphics.drawable.RippleDrawable" on path: DexPathList[[zip file "/data/app/org.qtproject.example-8.apk"],nativeLibraryDirectories=[/data/app-lib/org.qtproject.example-8, /vendor/lib, /system/lib]]
W/System.err(10313): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
W/System.err(10313): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
W/System.err(10313): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
W/System.err(10313): ... 26 more
W/System.err(10313): java.lang.ClassNotFoundException: android.graphics.drawable.AnimatedStateListDrawable
W/System.err(10313): at java.lang.Class.classForName(Native Method)
W/System.err(10313): at java.lang.Class.forName(Class.java:251)
W/System.err(10313): at java.lang.Class.forName(Class.java:216)
W/System.err(10313): at org.qtproject.qt5.android.ExtractStyle.getClass(ExtractStyle.java:395)
W/System.err(10313): at org.qtproject.qt5.android.ExtractStyle.<init>(ExtractStyle.java:99)
W/System.err(10313): at org.qtproject.qt5.android.QtActivityDelegate.loadApplication(QtActivityDelegate.java:512)
W/System.err(10313): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(10313): at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err(10313): at org.qtproject.qt5.android.bindings.QtLoader.loadApplication(QtLoader.java:237)
W/System.err(10313): at org.qtproject.qt5.android.bindings.QtLoader.startApp(QtLoader.java:647)
W/System.err(10313): at org.qtproject.qt5.android.bindings.QtActivityLoader.onCreate(QtActivityLoader.java:181)
W/System.err(10313): at org.qtproject.qt5.android.bindings.QtActivity.onCreate(QtActivity.java:269)
W/System.err(10313): at android.app.Activity.performCreate(Activity.java:5447)
W/System.err(10313): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
W/System.err(10313): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
W/System.err(10313): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
W/System.err(10313): at android.app.ActivityThread.access$800(ActivityThread.java:166)
W/System.err(10313): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
W/System.err(10313): at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err(10313): at android.os.Looper.loop(Looper.java:136)
W/System.err(10313): at android.app.ActivityThread.main(ActivityThread.java:5584)
W/System.err(10313): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(10313): at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err(10313): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
W/System.err(10313): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
W/System.err(10313): at dalvik.system.NativeStart.main(Native Method)
W/System.err(10313): Caused by: java.lang.NoClassDefFoundError: android/graphics/drawable/AnimatedStateListDrawable
W/System.err(10313): ... 26 more
W/System.err(10313): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.graphics.drawable.AnimatedStateListDrawable" on path: DexPathList[[zip file "/data/app/org.qtproject.example-8.apk"],nativeLibraryDirectories=[/data/app-lib/org.qtproject.example-8, /vendor/lib, /system/lib]]
W/System.err(10313): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
W/System.err(10313): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
W/System.err(10313): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
W/System.err(10313): ... 26 more
W/System.err(10313): java.lang.ClassNotFoundException: android.graphics.drawable.VectorDrawable
W/System.err(10313): at java.lang.Class.classForName(Native Method)
W/System.err(10313): at java.lang.Class.forName(Class.java:251)
W/System.err(10313): at java.lang.Class.forName(Class.java:216)
W/System.err(10313): at org.qtproject.qt5.android.ExtractStyle.getClass(ExtractStyle.java:395)
W/System.err(10313): at org.qtproject.qt5.android.ExtractStyle.<init>(ExtractStyle.java:100)
W/System.err(10313): at org.qtproject.qt5.android.QtActivityDelegate.loadApplication(QtActivityDelegate.java:512)
W/System.err(10313): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(10313): at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err(10313): at org.qtproject.qt5.android.bindings.QtLoader.loadApplication(QtLoader.java:237)
W/System.err(10313): at org.qtproject.qt5.android.bindings.QtLoader.startApp(QtLoader.java:647)
W/System.err(10313): at org.qtproject.qt5.android.bindings.QtActivityLoader.onCreate(QtActivityLoader.java:181)
W/System.err(10313): at org.qtproject.qt5.android.bindings.QtActivity.onCreate(QtActivity.java:269)
W/System.err(10313): at android.app.Activity.performCreate(Activity.java:5447)
W/System.err(10313): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
W/System.err(10313): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
W/System.err(10313): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
W/System.err(10313): at android.app.ActivityThread.access$800(ActivityThread.java:166)
W/System.err(10313): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
W/System.err(10313): at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err(10313): at android.os.Looper.loop(Looper.java:136)
W/System.err(10313): at android.app.ActivityThread.main(ActivityThread.java:5584)
W/System.err(10313): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(10313): at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err(10313): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
W/System.err(10313): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
W/System.err(10313): at dalvik.system.NativeStart.main(Native Method)
W/System.err(10313): Caused by: java.lang.NoClassDefFoundError: android/graphics/drawable/VectorDrawable
W/System.err(10313): ... 26 more
W/System.err(10313): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.graphics.drawable.VectorDrawable" on path: DexPathList[[zip file "/data/app/org.qtproject.example-8.apk"],nativeLibraryDirectories=[/data/app-lib/org.qtproject.example-8, /vendor/lib, /system/lib]]
W/System.err(10313): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
W/System.err(10313): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
W/System.err(10313): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
W/System.err(10313): ... 26 more
W/ResourceType(10313): Skipping entry 0x1080892 in package table 0 because it is not complex!
D/dalvikvm(10313): GC_CONCURRENT freed 7227K, 56% free 6322K/14364K, paused 2ms+4ms, total 38ms
D/dalvikvm(10313): Trying to load lib /data/app-lib/org.qtproject.example-8/libQtQuick2_Android.so 0x41c0caf0
D/ (10313): (null):0 ((null)): QML debugging is enabled. Only use this in a safe environment.
D/dalvikvm(10313): Added shared lib /data/app-lib/org.qtproject.example-8/libQtQuick2_Android.so 0x41c0caf0
D/dalvikvm(10313): No JNI_OnLoad found in /data/app-lib/org.qtproject.example-8/libQtQuick2_Android.so 0x41c0caf0, skipping init
D/StatusBarManagerService( 591): semi p:10313,o:t
D/OpenGLRenderer(10313): Enabling debug mode 0
D/dalvikvm(10313): GC_CONCURRENT freed 1644K, 65% free 5114K/14364K, paused 2ms+2ms, total 25ms
I/Timeline(10313): Timeline: Activity_idle id: [email protected] time:54858979
I/InputDispatcher( 591): Delivering touch to (10313): action: 0x0, toolType: 1
I/InputDispatcher( 591): Delivering touch to (10313): action: 0x1, toolType: 1
F/libc (10313): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 10365 (project.example)
I/DEBUG ( 163): pid: 10313, tid: 10365, name: project.example >>> org.qtproject.example <<<
I/DEBUG ( 163): [email protected] -k -t -z -d -o /data/log/dumpstate_app_native -m 10313
D/CrashAnrDetector( 591): pid: 10313, tid: 10365, name: project.example >>> org.qtproject.example <<<
E/android.os.Debug( 591): [email protected] > dumpstate -k -t -z -d -m 10313 -o /data/log/dumpstate_app_error
"org.qtproject.example" terminated.
我所知,目前對Qt的QtAndroidExtras
模塊。但我想用純Jni for Android。因爲我使用jni其他Android開發平臺(Qt,C++ Builder)。 當我試着用QAndroidJniObject::callStaticMethod
成員函數編譯這個應用程序時,我得到了Java Code worked!
的輸出,所以,它是有效的。但是當我嘗試用純jni函數(jni.h頭文件)編譯這個應用程序時,我看到Unfortunately app has stopped
,並且我得到了控制檯輸出。
AndroidClass.java目錄:MyApp/android/src/com/test/AndroidClass.java
AndroidClass.class目錄(用javac編譯):build-MyApp-Android_for_armeabi_v7a_GCC_4_9_Qt_5_7_0-Debug/com/test/AndroidClass.class
並且在build-MyApp-Android_for_armeabi_v7a_GCC_4_9_Qt_5_7_0-Debug/android-build/src/com/test/AndroidClass.class
相同的文件我如何工作的這個應用程式純JNI?謝謝。
我試過Android 4.4.4。我爲API 19編譯,但結果相同。 –