How to set up the FMOD audio library in Qt Creator for Android
-
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.
-
@8Observer8 I guess not. I built my app for Android 11 and 12 at first. And it did not work on Android 13. I had to add 13 support in the build.
-
@JoeCFD My only guess is that an app built for Android 11 doesn't work on Android 13 because it uses APIs that were removed in Android 13, but unless you're using backwards compatibility hacks, then early apps should work on more number of new devices. But this is only my assumption, which I myself have to verify by experience.
-
I currently have an Android 13 smartphone. I tried to run my music application using OpenAL. It works on smartphones with Android 13 and 7. This is very good, because I thought that I would have to make a separate build in the APK for each version of the smartphone, starting from Android 7 to13.
-
@8Observer8 What I did is to add all SDKs of Android 11, 12 and 13 to the project, but I made only one build . My app works fine in 11, 12 and 13.
-
@JoeCFD said in How to set up the FMOD audio library in Qt Creator for Android:
What I did is to add all SDKs of Android 11, 12 and 13 to the project
Last time you wrote that if the application is built for Android 7 and Android 12 SDK, then it will not work on Android 13. Interestingly, I was unable to remove the Android 12 SDK from Qt Creator. Qt Creator says that Android 12 SDK is required:
I don't have the Android 13 SDK installed, but my app works fine on Android 13 and Android 7: