How to import/link CSound when making JUCE Android App?

Hi everyone!

I downloaded precompiled libraries for Android from Csound download website (https://github.com/csound/csound/releases/download/6.16.1/csound-android-6.16.1.zip) and copied them into my project (to …\Builds\Android\app\libs). I set accordingly “Extra Library Search Paths” and “External Libraries to Link” in Projucer but when I build the project I get error:
skipping incompatible C:/Projects/building_csound/Csound_android_test1/Builds/Android/app/libs/armeabi-v7a/libcsoundandroid.so when searching for -lcsoundandroid

I get the same error when trying to build either for x64 or x86 emulator devices or for my phone.

What am I doing wrong?

Thanks!

Are you sure this is supported on the target device? Did you try linking to the arm64 libs?

When I do that, I get:
ninja: error: ‘…/…/…/…/libs/armeabi-v7a/libcsoundandroid.so’, needed by ‘…/…/…/…/build/intermediates/cxx/Debug/366d2749/obj/armeabi-v7a/libjuce_jni.so’, missing and no known rule to make it

So I think that armeabi-v7a is correct version…

I’m no expert, but I wouldn’t expect to see any references to armeabi-v7 if you are building for arm-v8?

Good observation @rory, thanks a lot! :slight_smile:

After some try & error attempts I think I found what is wrong. It seems that Android studio is in some kind of conflict with Projucer when libraries are copied manually inside App libs folder. I removed “Extra Library Search Paths” and just left “External Libraries to Link” and now it can build but only if I am not using the library, if I just link it.

There are no headers in the csound-android directory so I took ones from sources directory (https://github.com/csound/csound/archive/refs/tags/6.16.1.zip). It didn’t seem right from the beginning but I still tested it and it of course didn’t work.
If I include csound.hpp and try to make a csound object I get error: error: undefined reference to ‘csoundGetInputName’. If I try with AndroidCsound.hpp I get the same error.

Now, in my understanding in both cases csound.h can’t link with the csound-android library (libcsoundandroid.so) because headers and library simply don’t match, is that correct? If yes, do you know maybe where I can find right headers for the library? Or how to make things right without them? :confused:

I think these are the files you might be needing:

I was running in circle but I finally got it. @rory thanks again for helping

Here are the steps if anyone else gets into the same problem:

  1. Download precompiled csound libraries for android from here (https://github.com/csound/csound/releases/download/6.16.1/csound-android-6.16.1.zip)

  2. Download csound sources from here (https://github.com/csound/csound/archive/refs/tags/6.16.1.zip) - this is needed because of the headers that we need to work with the csoundandroid library

  3. Make a Projucer project with Android exporter

  4. Set needed parameters in Projucer so that you can work with needed libraries in Android Studio:

  • External Libraries to Link – csoundandroid, c++_shared, sndfile

  • Extra Library Search Paths - …/path/to/jniLibs/${ANDROID_ABI} → I copied jniLibs folder from csound-android folder into main folder of Android project but I am not sure this is absolutely necessary

  • Header Search Paths - …/path/to/include → this folder is inside csound sources folder but you can copy it also in your project

  • Architectures - armeabi-v7a arm64-v8a → I don’t know why but csound libraries for android are precompiled only for those two architectures

Disclosure: I didn’t make anything special so far and I am not 100% sure that everything is ok but I managed to link the library and make a csound object :cowboy_hat_face:

Great to hear that you got it going, and thanks for reporting back on what you did to get it working :+1:

@Lovre Did you manage to get this working with the emulator in Android Studio?

@rory On Windows I’m getting now the error “Error while waiting for device: The emulator process for AVD Pixel_5_API_30_64 has terminated.” but I think it has run on Mac without problems. :thinking:

I can test it again on Mac after the holidays so I can let you know for sure if it runs or not, if you want.

p.s. And this error I’m getting on Windows, I’m not sure it is related to csound :confused: it can be that something else is wrong with my Android Studio.

Hi @Lovre I managed to get it to work by setting USE_DOUBLE to 0. By default Csound will use double precision floating points for samples. Android doesn’t like this. I’m running Android studio on a Mac here myself, so I can’t say about other platforms.

1 Like

@rory @Lovre I tried following these steps but it didn’t work for me and I keep getting many errors. Have any of you successfully linked csound with juce for android? thank you.

Yes, I had to do this recently. I can’t recall however if I got it to run in the emulator, but no issues running directly on my phone from Android Studio. What are the errors you’re getting?

If I run by the emulator Android studio says that “csoundandroid.so is incompatible with elf_x86_64” so I only add “arm64-v8a” search path because my phone has this architecture. If I run on the phone I have no issues from android studio but I have an instant crush on the phone.

First of all, I tried to use a CSD in binary mode (one oscili for 3600 sec) and it does work in Windows, OSX, and IOS. I think that work by binaries file can be the problem in Android, so I tried to send by String orchestra and String score but I have the same crash. This is the log of the crash

01/30 18:09:37: Launching ‘app’ on Xiaomi M2002J9G.
App restart successful without requiring a re-install.
$ adb shell am start -n “com.yourcompany.csoundjuce/com.rmsl.juce.JuceActivity” -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 30264 on device ‘xiaomi-m2002j9g-d9e9ff1b’.
Capturing and displaying logcat messages from application. This behavior can be disabled in the “Logcat output” section of the “Debugger” settings page.
I/pany.csoundjuc: Late-enabling -Xcheck:jni
E/pany.csoundjuc: Unknown bits set in runtime_flags: 0x8000
I/Perf: Connecting to perf service.
I/FeatureParser: can’t find monet.xml in assets/device_features/,it may be in /vendor/etc/device_features
W/pany.csoundjuce: type=1400 audit(0.0:133249): avc: denied { read } for name=“u:object_r:vendor_displayfeature_prop:s0” dev=“tmpfs” ino=27950 scontext=u:r:untrusted_app:s0:c245,c257,c512,c768 tcontext=u:object_r:vendor_displayfeature_prop:s0 tclass=file permissive=0
E/libc: Access denied finding property “ro.vendor.df.effect.conflict”
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.yourcompany.csoundjuce, PID: 30264
java.lang.UnsatisfiedLinkError: dlopen failed: library “libcsoundandroid.so” not found
at java.lang.Runtime.loadLibrary0(Runtime.java:1071)
at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
at java.lang.System.loadLibrary(System.java:1667)
at com.rmsl.juce.Java.(Java.java:31)
at com.rmsl.juce.Java.initialiseJUCE(Native Method)
at com.rmsl.juce.JuceApp.onCreate(JuceApp.java:35)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1190)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6604)
at android.app.ActivityThread.access$1400(ActivityThread.java:227)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1890)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7584)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

I think that the problem is java.lang.UnsatisfiedLinkError: dlopen failed: library “libcsoundandroid.so” not found

Thanks for your help

I somehow missing this follow-up post, did you get it to work in the end?

Hi Rory,

I’m so sorry to lost your mail. Gmail send it to “spam” and I didn’t see it. I’ve fixed the libraries error and now csound is linked but unfortunately it does not work properly because it’s starting but not perform ksmps. I tried to force “performksmps” method by a time callback but it didn’t work. Csound seems to be frozen. Do you have any suggestions?

Best regards

I’m not sure what the problem is. How do you know it’s not performing a ksmps? Have you checked the return code for performKsmps()? And are you sending the Csound messages to logcat? That should give you some extra information. As I mentioned before, I haven’t had to run Csound on Android for some time, but I don’t recall having too many problems with it. The CsoundUnity package also features support for Android, and that works pretty much out of the box.