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)
[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
[Updated on 03.07.2016]
Along with the new circumstances given by the pd-for-android project update, I updated my blog posts as well. Take a look here:
Blog post: http://www.journal.deviantdev.com/pure-data-for-android-jcenter-gradle-dependecy/
Sample Project: http://www.journal.deviantdev.com/sample-libpd-android-studio/
[Original Answer]
Basically this question is answered in different ways, but I want to add another answer for sharing my thoughts. I documented and updated different ways of how to run libpd with android studio. I will summarize the essential steps:
Now you have two possible ways to get it working. You can build pd-for-android with the NDK and add the dependencies or you can add jniLibs.srcDirs = ['src', 'libs']" to the PdCore build.gradle. Normally you will choose the second way except you have to compile some externals not coming with pd-for-android by default.
Here you can find some posts, providing more details and a sample project for Android Studio:
Good luck!
I had the same problem and to fix it I had to tell the android gradle plugin where the jni files (.so) are:
android {
// omitted ...
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'jni/libpd/java']
resources.srcDirs = ['src', 'jni/libpd/java']
aidl.srcDirs = ['src', 'jni/libpd/java']
renderscript.srcDirs = ['src', 'jni/libpd/java']
// ** this is what was missing **
jniLibs.srcDirs = ['src', 'libs']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
You can check out the complete build.gradle file in a fork I made of the original libpd-for-android repository. I'm using there a newer version of the Android gradle plugin and it works great with Android Studio:
https://github.com/tkirshboim/pd-for-android/
-- Update from 30.06.2015 --
My pd-for-android fork was extended by @github/joebowbeer so that the gradle support is improved and you can create an .aar file using gradle and the Android NDK. So it's no longer necessary to copy the the pd-for-android code + binaries when creating a new Android project that uses pure data. The pull request for this updated fork should be merged soon to the master branch. Until then you can clone this fork from here:
https://github.com/joebowbeer/pd-for-android/tree/gradle_mods
I don't have enough reputation yet to comment on the answer by @sdaau to this question, it is however incorrect that Android Studio will not support NDK. NDK is supported in Android Studio from version 1.3 onwards. You can download it from here.
I've had the same problem. To make it short you have to instruct gradle to include *.so files as dependency in your project (it doesn't happen automatically)
I was able to solve my problem looking at this answer: https://stackoverflow.com/a/17974618 I hope it helps.
EDIT: I forgot: I also had to compile the PdCore project with ndk-build
. If you get an error regarding files in the folder opensl_stream
, make sure you got them correctly since they are a link to another git repo (i just copied them manually to my folder... not the best solution but it worked)
Cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With