Qt 5.14.2-Android项目中找不到Java类异常

问题描述

我无法告诉QtCreator编译Java文件(如果我在Java文件中放入随机单词,则该项目将继续编译)。 结果是在运行时,当我尝试从c ++调用类时,它给了我ClassNotFoundException。

这是我的.pro文件

TEMPLATE = app

QT += quick
android {
  QT += androidextras
}

CONfig += c++11 qtquickcompiler
CONfig -= debug_and_release

RESOURCES += resources.qrc

DEFInes += QT_DEPRECATED_WARNINGS

#DEFInes += QT_disABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

HEADERS += \
    android_gps_device.hpp

SOURCES += \
    main.cpp \
    android_gps_device.cpp

disTFILES += \
    android/AndroidManifest.xml \
    android/gradle/wrapper/gradle-wrapper.jar \
    android/gradlew \
    android/res/values/libs.xml \
    android/build.gradle \
    android/gradle/wrapper/gradle-wrapper.properties \
    android/gradlew.bat \
    android/src/me/mycompany/gps/GpsDevice.java

contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
    ANDROID_PACKAGE_SOURCE_DIR = \
        $$PWD/android
}

这是我的java文件

package me.mycompany.gps;

import android.content.Context;
import android.location.LocationManager;

public class GpsDevice {
  static boolean isEnabled(Context context) {
    try {
      LocationManager locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);
      return locationManager.isLocationEnabled();
    }
    catch(Exception e) {
      return false;
    }
  }
}

这是c ++方面:

#include <QtAndroid>
#include "android_gps_device.hpp"

AndroidGpsDevice::AndroidGpsDevice()
{
}

bool AndroidGpsDevice::enabled() const
{
  bool res = QAndroidJniObject::callStaticmethod<jboolean>("me/mycompany/gps/GpsDevice","isEnabled","(Landroid/content/Context;)Z",QtAndroid::androidContext().object());

  return res;
}

我在做什么错? 谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)