Hello. I made an example that works on desktop when I build it to EXE but crashes when I run APK on smartphone. I use 2.02.16 API version, JDK 17, NDK 22, Qt 6.2.4, and Redmi 4x (Android 7)
Settings:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
INCLUDEPATH += $$PWD/libs/fmod-2.2.16/inc
contains(ANDROID_TARGET_ARCH, armeabi-v7a)
{
ANDROID_EXTRA_LIBS += $$PWD/jniLibs/armeabi-v7a/libfmod.so
}
SOURCES += \
main.cpp \
widget.cpp
HEADERS += \
widget.h
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
RESOURCES += \
assets.qrc
APK is created after 1-2 minutes without problems. This is a source code of my example:
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QtWidgets/QWidget>
#include <fmod.h>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
private:
FMOD_SYSTEM *m_pSystem;
FMOD_SOUND *m_pSound;
};
#endif // WIDGET_H
widget.cpp
#include "widget.h"
#include <QtCore/QDebug>
#include <QtCore/QFile>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
FMOD_System_Create(&m_pSystem, FMOD_VERSION);
FMOD_System_Init(m_pSystem, 32, FMOD_INIT_NORMAL, 0);
QString soundPath(":/assets/audio/music.wav");
QFile f(soundPath);
if (!f.open(QIODevice::ReadOnly))
{
qDebug() << "Faild to open the file: " << soundPath;
return;
}
QByteArray soundData = f.readAll();
FMOD_CREATESOUNDEXINFO* exinfo = new FMOD_CREATESOUNDEXINFO();
exinfo->length = static_cast<unsigned int>(soundData.length());
exinfo->cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
FMOD_System_CreateSound(m_pSystem, soundData.data(), FMOD_OPENMEMORY, exinfo, &m_pSound);
FMOD_Sound_SetMode(m_pSound, FMOD_LOOP_OFF);
FMOD_System_PlaySound(m_pSystem, m_pSound, 0, false, 0);
}
Widget::~Widget()
{
}
main.cpp
#include "widget.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
I use armeabi-v7a
to build a release:
I tried without FMOD and it runs on smartphone without problems. But my example above crashes with this report:
Build fingerprint: âXiaomi/santoni/santoni:7.1.2/N2G47H/9.6.27:user/release-keysâ
Revision: â0â
ABI: âarmâ
pid: 11662, tid: 11682, name: qtMainLoopThrea >>> org.qtproject.example.fmode_2d_qt6_cpp <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Abort message: âart/runtime/java_vm_ext.cc:475] JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.ClassNotFoundException: Didnât find class âorg.fmod.AudioDeviceâ on path: DexPathList[[zip file â/data/app/org.qtproject.example.fmode_2d_qt6_cpp-1/base.apkâ],nativeLibraryDirectories=[/data/app/org.qtproject.example.fmode_2d_qt6_cpp-1/lib/arm, /data/app/org.qtproject.example.fmode_2d_qt6_cpp-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]â
r0 00000000 r1 00002da2 r2 00000006 r3 00000008
r4 c7780978 r5 00000006 r6 c7780920 r7 0000010c
r8 00000000 r9 0000000a sl 00000fbd fp da07b900
ip 0000000b sp c777f610 lr e843f2d7 pc e8441b58 cpsr 200f0010
backtrace:
#00 pc 00049b58 /system/lib/libc.so (tgkill+12)
#01 pc 000472d3 /system/lib/libc.so (pthread_kill+34)
#02 pc 0001d575 /system/lib/libc.so (raise+10)
#03 pc 000190c1 /system/lib/libc.so (__libc_android_abort+34)
#04 pc 00017124 /system/lib/libc.so (abort+4)
#05 pc 0031c3d9 /system/lib/libart.so (_ZN3art7Runtime5AbortEPKc+328)
#06 pc 000b569d /system/lib/libart.so (_ZN3art10LogMessageD2Ev+1132)
#07 pc 0023ab55 /system/lib/libart.so (ZN3art9JavaVMExt8JniAbortEPKcS2+1664)
#08 pc 0023ad47 /system/lib/libart.so (_ZN3art9JavaVMExt9JniAbortVEPKcS2_St9__va_list+58)
#09 pc 000cb09b /system/lib/libart.so (_ZN3art11ScopedCheck6AbortFEPKcz+46)
#10 pc 000cac87 /system/lib/libart.so (_ZN3art11ScopedCheck11CheckThreadEP7_JNIEnv+362)
#11 pc 000c9c9f /system/lib/libart.so (_ZN3art11ScopedCheck22CheckPossibleHeapValueERNS_18ScopedObjectAccessEcNS_12JniValueTypeE+26)
#12 pc 000c917b /system/lib/libart.so (_ZN3art11ScopedCheck5CheckERNS_18ScopedObjectAccessEbPKcPNS_12JniValueTypeE+802)
#13 pc 000cbe49 /system/lib/libart.so (_ZN3art8CheckJNI6NewRefEPKcP7_JNIEnvP8_jobjectNS_15IndirectRefKindE+452)
#14 pc 003382fd /system/lib/libart.so (_ZN3art6Thread22SetClassLoaderOverrideEP8_jobject+32)
#15 pc 0023c857 /system/lib/libart.so (ZN3art9JavaVMExt17LoadNativeLibraryEP7_JNIEnvRKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEP8_jobjectP8_jstringPS9+1878)
#16 pc 00003167 /system/lib/libopenjdkjvm.so (JVM_NativeLoad+178)
#17 pc 00584c6d /system/framework/arm/boot.oat (offset 0x51c000) (java.lang.Runtime.nativeLoad+144)
#18 pc 005848ad /system/framework/arm/boot.oat (offset 0x51c000) (java.lang.Runtime.doLoad+136)
#19 pc 005859dd /system/framework/arm/boot.oat (offset 0x51c000) (java.lang.Runtime.load0+368)
#20 pc 0059e383 /system/framework/arm/boot.oat (offset 0x51c000) (java.lang.System.load+78)
#21 pc 000a9b41 /system/lib/libart.so (art_quick_invoke_stub_internal+64)
#22 pc 00406ff5 /system/lib/libart.so (art_quick_invoke_static_stub+228)
#23 pc 000b0dff /system/lib/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+178)
#24 pc 001edfed /system/lib/libart.so (_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+200)
#25 pc 001e859d /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+492)
#26 pc 003ffaf9 /system/lib/libart.so (MterpInvokeStatic+236)
#27 pc 0009cb14 /system/lib/libart.so (ExecuteMterpImpl+14612)
#28 pc 001cb8c7 /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+286)
#29 pc 001d042f /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
#30 pc 001e8583 /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+466)
#31 pc 003ff61b /system/lib/libart.so (MterpInvokeInterface+834)
#32 pc 0009cb94 /system/lib/libart.so (ExecuteMterpImpl+14740)
#33 pc 001cb8c7 /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+286)
#34 pc 001d042f /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
#35 pc 001e8583 /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+466)
#36 pc 003ff61b /system/lib/libart.so (MterpInvokeInterface+834)
#37 pc 0009cb94 /system/lib/libart.so (ExecuteMterpImpl+14740)
#38 pc 001cb8c7 /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+286)
#39 pc 001d0399 /system/lib/libart.so (_ZN3art11interpreter30EnterInterpreterFromEntryPointEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameE+92)
#40 pc 003f63e7 /system/lib/libart.so (artQuickToInterpreterBridge+706)
#41 pc 000ae593 /system/lib/libart.so (art_quick_to_interpreter_bridge+34)
#42 pc 005a22e9 /system/framework/arm/boot.oat (offset 0x51c000) (java.lang.Thread.run+52)
#43 pc 000a9b41 /system/lib/libart.so (art_quick_invoke_stub_internal+64)
#44 pc 00406eed /system/lib/libart.so (art_quick_invoke_stub+232)
#45 pc 000b0dd5 /system/lib/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+136)
#46 pc 00317349 /system/lib/libart.so (_ZN3artL18InvokeWithArgArrayERKNS_33ScopedObjectAccessAlreadyRunnableEPNS_9ArtMethodEPNS_8ArgArrayEPNS_6JValueEPKc+56)
#47 pc 00318115 /system/lib/libart.so (_ZN3art35InvokeVirtualOrInterfaceWithJValuesERKNS_33ScopedObjectAccessAlreadyRunnableEP8_jobjectP10_jmethodIDP6jvalue+256)
#48 pc 0032f29d /system/lib/libart.so (_ZN3art6Thread14CreateCallbackEPv+848)
#49 pc 00046da3 /system/lib/libc.so (_ZL15__pthread_startPv+22)
#50 pc 00019b0d /system/lib/libc.so (__start_thread+6)