How to set up the FMOD audio library in Qt Creator for Android
-
I tried this:
INCLUDEPATH += $$PWD/libs/fmod-2.2.16/inc contains(ANDROID_TARGET_ARCH, armeabi-v7a) { ANDROID_EXTRA_LIBS = \ $$PWD/libs/fmod-2.2.16/lib/armeabi-v7a/libmapbox-gl.so }
-
Sorry, I forgot to change the name of library to "libfmod.so". But the errors are the same. Qt doesn't see the "libfmod.so" library:
I try to build with
armeabi-v7a
for Release to build an APK and run it on a real smartphone: -
The build process was finished without problems and the APK file was created with these settings:
INCLUDEPATH += $$PWD/libs/fmod-2.2.16/inc contains(ANDROID_TARGET_ARCH, armeabi-v7a) { LIBS += $$PWD/libs/fmod-2.2.16/lib/armeabi-v7a/libfmod.so }
But when I run it on real smartphone the app was crashed. Why? What should I try?
I built this example for Desktop before and it works without crash. Music played.
-
I found this answer here: https://stackoverflow.com/questions/47170950/qt-creator-and-android-run-on-emulator-but-crash-on-hardware-device
Finally after much digging.
The compiler used with QtCreator generates armeabi-v7a lib files.
Those files are included into the /libs/ folder on the apk.
Our project required to use some other external libs that were also compiled for other architectures. The folder /libs/ of the generated apk contained libs for those different architecture, but the main project was available only for the armeabi-v7a.
Therefore the app would be started and try to find the lib to the preferred architecture and would crash right away.
The solution is to force using only the available architecture.
This is done by adding this to the build.gradle script
defaultConfig { ndk { abiFilters 'armeabi-v7a' } }
But where should I add it?
-
I found where I should add it:
C:\Qt\6.2.4\android_armv7\src\android\templates\build.gradle
I add it to
build.gradle
here:defaultConfig { resConfig "en" minSdkVersion qtMinSdkVersion targetSdkVersion qtTargetSdkVersion ndk.abiFilters = qtTargetAbiList.split(",") ndk { abiFilters 'armeabi-v7a' } }
But it did not help. The app is crashed on real smartphone.
-
I tried to rerun Qt and delete the old build to APK. But it did not help.
But I opened a report of MIUI about errors on smartphone:
java.lang.UnsatisfiedLinkError: dlopen failed: library "libfmod.so" not found
at java.lang.Runtime.load0(Runtime.java: 908)
at java.lang.System.load(System.java: 1537)
at org.qtproject.qt.android.QtNative$4.run(QtNative.java:536)
at org.qtproject.qt.android.QtThread$2.run(QtThread.java:87)
at org.qtproject.qt.android.QtThread$1.run(QtThread.java:61)
at java.lang.Thread.run(Thread.java:760) -
I changed LIBS to ANDROID_EXTRA_LIBS like here: https://www.qtcentre.org/threads/60779-Using-3rd-part-static-library-with-QT-Creator-in-Win7?p=269120#post269120
Since you're linking dynamically against libusb you need to deploy the library with your application. You can use ANDROID_EXTRA_LIBS to achieve that.
Have a look at the documentation: http://qt-project.org/doc/qt-5/deployment-android.html
contains(ANDROID_TARGET_ARCH, armeabi-v7a) { ANDROID_EXTRA_LIBS += $$PWD/jniLibs/armeabi-v7a/libfmod.so }
Now I have another errors after a crash on the real device:
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 200f0010backtrace:
#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) -
I have created a few topics:
- Official FMOD forum: https://qa.fmod.com/t/qt-application-with-fmod-audio-library-crashes-on-launch-on-android/20561
- Stack Overflow: https://stackoverflow.com/questions/76928386/qt-application-with-fmod-audio-library-crashes-on-launch-on-android
- Qt Centre: https://www.qtcentre.org/threads/63390-Adding-external-library-into-Qt-Android-project
-
@8Observer8 said in How to set up the FMOD audio library in Qt Creator for Android:
ANDROID_EXTRA_LIBS
I guess
if your app is built with Qt6, use QT_ANDROID_EXTRA_LIBS.
Use ANDROID_EXTRA_LIBS for Qt5How do I view the contents of an APK file?
APK files are saved in a compressed .ZIP format and can be opened by any Zip decompression tool. Therefore, if you would like to explore the contents of an APK file, you can rename the file extension to ".zip" and open the file, or you can open the file directly through a Zip application's open dialog box.
Open or list your apk file to make sure these libs are added in.
Try the latest Qt6 if you prefer Qt6. Qt-6.2 is new in Qt 6.
I would prefer to use Qt5 for this. Especially your Android version is so old. -
@JoeCFD said in How to set up the FMOD audio library in Qt Creator for Android:
How do I view the contents of an APK file?
You can download it here: https://www.dropbox.com/scl/fi/m7hk76cia49451mhsoiny/android-build-with-fmod-for-forums.apk?rlkey=h2cnav1e6bl7s3ixidqi4nnsf&dl=1
Could you try to run it on your smartphone?
-
@JoeCFD said in How to set up the FMOD audio library in Qt Creator for Android:
Try the latest Qt6 if you prefer Qt6. Qt-6.2 is new in Qt 6.
Sorry. I forgot to write what I use. I use: FMODE 2.02.16 API version, JDK 17, NDK 22, Qt 6.2.4, and Redmi 4x (Android 7)
-
@JoeCFD said in How to set up the FMOD audio library in Qt Creator for Android:
Open or list your apk file to make sure these libs are added in.
Yes,
libfmod.so
is there. But How to make sure that the path is corrent? -
@8Observer8 they are all together. No path issue here.
-
@JoeCFD said in How to set up the FMOD audio library in Qt Creator for Android:
they are all together. No path issue here.
I mean, maybe Qt try to find it on the wrong path that I wrote in pro-file. I found somewhere that the folder must be named
jniLibs
:contains(ANDROID_TARGET_ARCH, armeabi-v7a) { ANDROID_EXTRA_LIBS += $$PWD/jniLibs/armeabi-v7a/libfmod.so }
-
I tried to use
lib
instead ofjniLibs
but the result is the same.contains(ANDROID_TARGET_ARCH, armeabi-v7a) { ANDROID_EXTRA_LIBS += $$PWD/lib/armeabi-v7a/libfmod.so }
-
@8Observer8 Very few people have phones with Android 7.
-
@JoeCFD said in How to set up the FMOD audio library in Qt Creator for Android:
Very few people have phones with Android 7.
I think the smaller the version, the more you can capture the audience. Let's say if you build for Android 4, then the application will run on Android 4, 5, 6, 7, 8, 9, 10, 11 and so on. But if you build on the latest version of Android, then the audience will be very small.
-
@8Observer8 then you need to add the support up to Android 13. Did you do it? Or you simply made Android 7 support?
my app supports Android 11, 12 and 13.
-
@JoeCFD said in How to set up the FMOD audio library in Qt Creator for Android:
my app supports Android 11, 12 and 13.
I think Android is backward compatible. That is, if I created applications with the selected Android 4, this means that the application will work not only on Android 4, but also on Android 5, 12 and 13.