androidandroid-studiolibpd

Using libpd in Android Studio


So I've got the git repo from https://github.com/libpd/pd-for-android and created a new blank project in Android Studio for my "AmazingSynthesizer".

I used the "Import Module" wizard to import PdCore and AndroidMidi. Then, right clicked on "app" to view my "Module Settings". Under dependencies I've added PdCore as a module dependency. Also, I added AndroidMidi as a module dependency for "PdCore".

So far, that seemed right to my. My app's build.gradle includes the libraries and I can import PdDispatcher in my MainActivity. The problem is, that it still seems to miss the native libraries (I think!).

The very basic example code from the official libpd book (Making Musical Apps by Peter Brinkmann)

PdAudio.initAudio(sampleRate, 0, 2, 8, true);

fails miserably

java.lang.UnsatisfiedLinkError: Couldn't load pd from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.app.amazingsynthesizer-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.app.amazingsynthesizer-1, /vendor/lib, /system/lib]]]: findLibrary returned null
        at java.lang.Runtime.loadLibrary(Runtime.java:358)
        at java.lang.System.loadLibrary(System.java:526)
        at org.puredata.core.PdBase.<clinit>(PdBase.java:55)
        at org.puredata.android.io.PdAudio.startAudio(PdAudio.java:86)
        at com.app.amazingsynthesizer.MainActivity.onResume(MainActivity.java:62)
        at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192)
        at android.app.Activity.performResume(Activity.java:5310)
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2764)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2803)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2238)
        at android.app.ActivityThread.access$800(ActivityThread.java:135)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5001)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
        at dalvik.system.NativeStart.main(Native Method)

Solution

  • [Updated 1/17/2016]

    Now that the pd-for-android library artifact has been published to jCenter, the simplest solution got even simpler: no clones, no imports; just edit your project's build.gradle file and add a compile dependency on org.puredata.android:pd-core:1.0.0.

    See pd-for-android's updated README for help.

    Original accepted answer:

    The simplest way to get up and running is to copy the prebuilt .so files to:

    AmazingSynthesizer/src/main/jniLibs

    You'll need libpd.so and libpdnativeopensl.so for the architectures that you are targeting, for example:

    AmazingSynthesizer/src/main/jniLibs/armeabi/libpd.so AmazingSynthesizer/src/main/jniLibs/armeabi/libpdnativeopensl.so