尝试从 c++ 端创建一个 java 类,但不断崩溃
appBucksAdv.java
package adv;
import org.qtproject.qt5.android.bindings.QtApplication;
import org.qtproject.qt5.android.bindings.QtActivity;
import android.os.Bundle;
public class appBucksAdv extends QtActivity
{
}
简单JNI.hpp
#include <QObject>
#include <QtAndroidExtras/QAndroidJniObject>
class simpleJNI : public QObject
{
Q_OBJECT
public:
explicit simpleJNI(QObject *parent = nullptr);
private:
QAndroidJniObject advClass_;
};
简单JNI
.cpp#include "simpleJNI.hpp"
simpleJNI::simpleJNI(QObject *parent) :
QObject(parent),
advClass_("adv/appBucksAdv") //crash when I create the java class
{
}
错误消息 : # W/dalvikvm(21397): dvmFindClassByName 拒绝'org/qtproject/qt5/android/QtMessageDialogHelper'
# D/dalvikvm(21397): Try to load lib/data/data/org.qtproject.example.androidTest/lib/libQt5QuickParticles.so 0x4176efd0
# D/dalvikvm(21397): Shared lib '/data/data/org.qtproject.example.androidTest/lib/libQt5QuickParticles.so' 已加载到同一个 CL 0x4176efd0
# D/dalvikvm(21397): Try to load lib/data/data/org.qtproject.example.androidTest/lib/libandroidTest.so 0x4176efd0
# D/dalvikvm(21397): 添加了共享库/data/data/org.qtproject.example.androidTest/lib/libandroidTest.so 0x4176efd0
# D/dalvikvm(21397): 在/data/data/org.qtproject.example.androidTest/lib/libandroidTest.0x4176efd0 so 中找不到JNI_OnLoad,跳过 init
# W/Qt (21397): kernel/qcoreapplication.cpp:416 (QCoreApplicationPrivate::QCoreApplicationPrivate(int&, char**, uint)): 警告:QApplication 未在 main() 线程中创建。
# W/dalvikvm(21397): dvmFindClassByName 拒绝'org/qtproject/qt5/android/QtNativeInputConnection'
# W/dalvikvm(21397): dvmFindClassByName 拒绝'org/qtproject/qt5/android/QtExtractedText'
1.完整消息
2.代码
您是否加载了正确的活动? 您需要编辑清单以使其加载您的自定义活动。您还应该避免自己调用QtActivity类的构造函数(advClass_("adv/appBucksAdv")),因为它会尝试再次准备应用程序。您可能想要的是活动的句柄,并且由于您已经在扩展 QtActivity 类,只需添加一个返回其句柄的静态函数。
例如:
爪哇岛:
public class appBucksAdv extends QtActivity
{
...
static appBucksAdv getActivity() { return thisActivity; }
...
}
C++
QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("adv/appBucksAdv",
"getActivity",
"()Ladv/appBucksAdv;");