I want to use OpenSL` ES only when available i.e. if Android version >= 2.3
Currently I have in Android.mk
LOCAL_LDLIBS += -lOpenSLES
But this won’t work if Android version < 2.3
Can I somehow load Open SL library dynamically only if Android version >= 2.3, maybe using System.loadLibrary ?
Use
Build.VERSIONto check the API version before you load the library and if it’s lower than API 9, don’t load it.Example:
[edit]
OR if you want to have one native library, loading OpenSL ES dynamically, you can use
dlopen. You can find an example on stackoverflow: https://stackoverflow.com/a/1142169/1145705