Using libpd in Android Studio

So, I have a git repo from https://github.com/libpd/pd-for-android and created a new empty project in Android Studio for my "AmazingSynthesizer".

I used the Import Module wizard to import PdCore and AndroidMidi. Then right-click on the “application” to view my “Module Settings”. In the dependencies, I added PdCore as a module dependency. In addition, I added AndroidMidi as a module dependency for "PdCore".

Until now, this seemed right to me. My build.gradle application includes libraries, and I can import PdDispatcher into my MainActivity. The problem is that it still seems to be missing native libraries (I think!).

The simplest example code from the official libpd book (Creating Music Applications by Peter Brinkman)

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

fails

 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) 
+6
source share
5 answers

[Updated 01/17/2016]

Now that the pd-for-android library artifact has been published in jCenter, the simplest solution is even simpler: no clones, no imports; just edit the build.gradle project build.gradle and add the compilation dependency on org.puredata.android:pd-core:1.0.0 .

See pd-for-android updated README for help.

Original accepted answer:

The easiest way to get up and run is to copy the pre-built .so files:

AmazingSynthesizer / SRC / Primary / jniLibs

For architecture, you will need libpd.so and libpdnativeopensl.so that you are oriented, for example:

AmazingSynthesizer / SRC / Primary / jniLibs / armeabi / libpd.so AmazingSynthesizer / SRC / Primary / jniLibs / armeabi / libpdnativeopensl.so

+7
source

[Updated 07/03/2016]

Along with the new circumstances posed by updating the pd-for-android project, I also updated my blog posts. Look at here:

Blog post: http://www.journal.deviantdev.com/pure-data-for-android-jcenter-gradle-dependecy/

Project example: http://www.journal.deviantdev.com/sample-libpd-android-studio/


[Original answer]

Basically this question answers differently, but I want to add another answer for the exchange of thoughts. I have documented and updated various ways to start libpd using android studio. I will summarize the main steps:

  • Get Android Studio
  • Download pd-for-android from GitHub
  • Create a new project in Android Studio
  • Import AndroidMidi as a module in Android Studio
  • Import PDCore as a module in Android Studio
  • Add dependency for AndroidMidi in PDCore
  • Add dependency for PDCore to your application

You now have two possible ways to make it work. You can create pd-for-android using the NDK and add dependencies, or you can add jniLibs.srcDirs = ['src', 'libs'] in PdCore build.gradle. Usually you choose the second method, except that you have to compile some external elements that are not in pd-for-android by default.

Here you can find several posts, providing more details and an example project for Android Studio:

Good luck

+7
source

I had the same problem, and to fix it I had to tell the android gradle plugin where 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 the complete build.gradle file in a fork made from the original libpd-for-android repository. I use there a newer version of the Android gradle plugin, and it works fine with Android Studio:

https://github.com/tkirshboim/pd-for-android/

- Update as of June 30, 2015 -

My pd-for-android fork has been extended by @ github / joebowbeer so that gradle support is improved and you can create a .aar file using gradle and Android NDK. Therefore, you no longer need to copy the pd-for-android code + binaries when creating a new Android project that uses clean data. The pull request for this updated fork should soon be merged with the master branch . Until then, you can clone this fork from here:

https://github.com/joebowbeer/pd-for-android/tree/gradle_mods

I still do not have enough reputation to comment on @sdaau 's answer to this question, however it is not true that Android Studio will not support NDK. NDK is supported in Android Studio from version 1.3 onwards . You can download it from here .

+3
source

I had the same problem. To do this briefly, you must tell gradle to include * .so files depending on your project (this does not happen automatically)

I was able to solve my problem by looking at this answer: fooobar.com/questions/12706 / ... I hope this helps.

EDIT: I forgot: I also had to compile the PdCore project using ndk-build . If you get an error message in the files in the opensl_stream folder, make sure you got them correctly, as they are a link to another git repository (I just copied them manually into my folder ... not the best solution, but it worked)

Greetings

+2
source

Thanks to @ kirsh300's answer , I got a newer git libpd repo for Android, but the build process was not trivial for me. Since this is likely to remain complicated (see Android Studio "Current NDK support is deprecated and out ), below is a bash script of what I needed to do to get libpd for Android for my old Linux application.

The first problem is that my installation is done in non-standard directories. Then I used the SDK from the old (er) Android Studio Bundle for Linux, 135.1078000 (since 20140321); By default it is equal to max 19 API; and does not install other APIs by default. However, the current revision of libpd applies to both API 17 and API 21. I manually installed API 17 by calling the $ANDROID_HOME/tools/android command, which is the Android SDK Manager, and I reduced API 21 to 19 by correcting the files in the script below. So, my Android SDK manager shows for installed:

sdk.png

The second problem is that with this SDK, gradlew appears, which is version 1.10, and the current version of gradlew marked in the libpd repo is 2.4 (on the first call, it will try to download the correct version of gradle ). Remember that you do not need to call gradlew from the SDK because it does not understand, say, android.ndkDirectory ("Could not find the property" ndkDirectory "on com.android.build.gradle.LibraryExtension_Decorated @ 3e3c83") or variant.outputs.each ("Could not find property exits" on com .android.build.gradle.internal.api.LibraryVariantImpl_Decorated@ 97447e ") builds in build.gradle scripts - thus gradlew 2.4 from the repo (hence the relative path in the script).

Here is the script:

 #!/usr/bin/env bash # wget http://dl.google.com/android/studio/install/0.5.2/android-studio-bundle-135.1078000-linux.tgz # wget http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86.bin # unpack downloads - and modify these to your actual absolute paths (also for JAVA_HOME below): ADTSDK=/path/to/adt-bundle-linux-x86-20140321/sdk ADNDK=/path/to/android-ndk-r10e # these seem to not really matter? nvm, keep: export ANDROID_HOME=$ADTSDK export ANDROID_NDK_HOME=$ADNDK set -x # only run if the subdirectory pd-for-android not created yet: if [ ! -d "pd-for-android" ]; then #git clone https://github.com/libpd/pd-for-android.git # no, OLD! git clone https://github.com/tkirshboim/pd-for-android.git cd pd-for-android # checkout specific version to make sure this test works when the repo changes: git checkout -f c5ea734c5aac7f2d37141e287bd0102706d54e55 # create root/top-level local.properties, esp. for sdk.dir: echo "ndk.dir=$ADNDK" > local.properties echo "sdk.dir=$ADTSDK" >> local.properties # downgrade API version: sed -i 's_compileSdkVersion 21_compileSdkVersion 19 //21_' PdTest/build.gradle sed -i 's_buildToolsVersion "21.1.2"_buildToolsVersion "19.1" //"21.1.2"_' PdTest/build.gradle sed -i "s_targetSdkVersion 21_targetSdkVersion 19 //21_" PdTest/build.gradle sed -i 's_compileSdkVersion 21_compileSdkVersion 19 //21_' CircleOfFifths/build.gradle sed -i 's_buildToolsVersion "21.1.2"_buildToolsVersion "19.1" //"21.1.2"_' CircleOfFifths/build.gradle sed -i "s_targetSdkVersion 21_targetSdkVersion 19 //21_" CircleOfFifths/build.gradle sed -i 's_compileSdkVersion 21_compileSdkVersion 19 //21_' ScenePlayer/build.gradle sed -i 's_buildToolsVersion "21.1.2"_buildToolsVersion "19.1" //"21.1.2"_' ScenePlayer/build.gradle sed -i "s_targetSdkVersion 21_targetSdkVersion 19 //21_" ScenePlayer/build.gradle sed -i 's_compileSdkVersion 21_compileSdkVersion 19 //21_' Voice-O-Rama/build.gradle sed -i 's_buildToolsVersion "21.1.2"_buildToolsVersion "19.1" //"21.1.2"_' Voice-O-Rama/build.gradle sed -i "s_targetSdkVersion 21_targetSdkVersion 19 //21_" Voice-O-Rama/build.gradle cd PdCore sed -i 's_compileSdkVersion 21_compileSdkVersion 19 //21_' build.gradle sed -i "s_buildToolsVersion '21.1.2'_buildToolsVersion '19.1' //'21.1.2'_" build.gradle # The SDK Build Tools revision (19.0.3) is too low for project ':PdCore'. Minimum required is 19.1.0 - install via Android SDK manager sed -i "s_targetSdkVersion 21_targetSdkVersion 19 //21_" build.gradle # check if tasks pass: ../gradlew tasks || { echo 'tasks failed' ; exit 1; } # pulls gradle-2.4-all.zip; # build: # must specify JAVA_HOME here, else "FAILURE: Build failed ... Could not find tools.jar" JAVA_HOME=/path/to/jdk1.6.0_45 ../gradlew assembleRelease cd ../.. fi 
0
source

Source: https://habr.com/ru/post/974324/


All Articles