libpd / pd-for-android

Pure Data for Android
352 stars 91 forks source link

Unsatisfied link error on arm64 devices #60

Closed keirong closed 6 years ago

keirong commented 7 years ago

I'm getting errors when initialising the library on arm64 devices (I have the Nexus 6P) and am getting the following error:

java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.myapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.bytegeist.tonal.pro-1/lib/arm64, /data/app/com.myapp-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]] couldn't find "libpd.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:984)
at java.lang.System.loadLibrary(System.java:1530)
at org.puredata.core.PdBase.<clinit>(PdBase.java:55)
at org.puredata.core.PdBase.implementsAudio(Native Method)
at org.puredata.android.io.PdAudio.isRunning(PdAudio.java:122)
at org.puredata.android.io.PdAudio.initAudio(PdAudio.java:57)

I looked in the exploded aar folder and there are folders for armeabi, armeabi-v7a and x86 but I can't see folders for arm64 or any of the variants listed in the error. Is it possible to get a release with the native files compiled for arm64?

EDIT: it is possible to work around this by adding a few tweaks as outlined in this article but it is still just a workaround, ideally the library should be built with arm64 in mind

tkirshboim commented 7 years ago

Hi @keirong ,

thanks for reporting this issue. I don't see any reason not to add arm64-v8a support so I've added it and created a pull request. It would be great if you could check out the change I did and say if it solves the problem for you.

joebowbeer commented 7 years ago

@keirong The native libs from the apk are selected at install time. The 32-bit versions of libpd work fine on 64-bit Android platforms, but if an apk includes any 64-bit native libs, then all of its native libs need to be built for 64-bit. I assume your apk contains some 64-bit native lib, or else you would not have this problem. Are you able to workaround the issue by adding an ndk abiFilters to your build.gradle?

The potential problems with adding 64-bit versions to libpd-for-android are:

See:

tkirshboim commented 7 years ago

@joebowbeer ok, those are all good points I didn't consider. @keirong given what Joe wrote here and that there is a working solution for the issue you reported, could you maybe explain a bit further why you think pd-for-android should be built also for arm64-v8a?

keirong commented 7 years ago

@tkirshboim I experienced the error due to the inclusion of another library with 64-bit native lib binaries, so I used the ndk abiFilters workaround that i mentioned in my initial post which does work, however as i said it is just a workaround, and I assumed compiling and testing the native libraries for 64-bit would not be difficult as it is just the extra parameter when compiling.

I suppose that the 64-bit device market on android is fairly slim at the moment, and considering that the 32-bit version works it isn't that big a problem, so this issue can be put on hold until the 64-bit market/support for other libraries grows, but I don't believe it should be completely disregarded considering other libraries out there are starting to support 64-bit (hence why i experienced the issue in the first place).

EDIT: I found a better workaround on the ReactNative article @joebowbeer linked to; if you use the abiFilters you explicitly say you are only supporting those specific architectures, which means when you upload your apk to the Play Store it excludes some 64-bit devices from the supported list of devices. However if you remove all 64-bit libraries in the packagingOptions of the apk like so:

 packagingOptions {
        exclude '/lib/mips64/**'
        exclude '/lib/arm64-v8a/**'
        exclude '/lib/x86_64/**'
    }

then the the device targeting on the Play Store includes the excluded 64-bit devices again.

joebowbeer commented 7 years ago

@keirong I don't want to ignore the need for a 64-bit build, but I do want to note that generating a 64-bit build needs additional testing, and may impact existing clients if they rebuild without reading the fine print (without adding compensating abiFilters). It may be appropriate to bump the major version when 64-bit support is ready.

Can you test the 64-bit build and send some feedback?

I don't understand how the abiFilters can affect the targeted devices in Google Play. Does abiFilters have any representation in the APK's AndroidManifest?

rpattabi commented 7 years ago

@keirong In addition to @joebowbeer's question, for the sake of completeness, could you confirm if you did all of the following to address this issue?

  1. Update to gradle.build with abiFilters
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
  1. Exclude unwanted libs

        packagingOptions {
            exclude '/lib/mips64/**'
            exclude '/lib/arm64-v8a/**'
            exclude '/lib/x86_64/**'
        }
  2. Update to gradle.properties in the project root

        android.useDeprecatedNdk=true

This is what this article mentions. I am skeptical about the deprecated ndk suggestion, considering the age of this article.

keirong commented 7 years ago

Sorry for the delay on this I have been sidetracked with work and haven't had a chance to reply; I used the packagingOptions to exclude any 64bit library builds in other libraries I've included to ensure that 32bit versions are used instead and it appeared to work:

packagingOptions {
            exclude '/lib/mips64/**'
            exclude '/lib/arm64-v8a/**'
            exclude '/lib/x86_64/**'
        }
rpattabi commented 7 years ago

@keirong Thanks for the update. I also notice that libpd.so is not available for mips as well. So probably that shall be excluded as well.

rpattabi commented 6 years ago

I have packagingOptions excluding 64bit builds as mentioned above. However, I still get this problem from a device (Intex / Aqua Strong 5.2 / Android 6.0)

Fatal Exception: java.lang.UnsatisfiedLinkError: 
dalvik.system.PathClassLoader[DexPathList[[zip file "/mnt/expand/566d2f2a-879c-4f22-c943-
249d70513fdf/app/myapp-1/base.apk"],nativeLibraryDirectories=[/mnt/expand/566d2f2a-879c-4f22-
c943-249d70513fdf/app/myapp-1/lib/arm64, /vendor/lib64, /system/lib64]]] 
couldn't find "libpd.so"
       at java.lang.Runtime.loadLibrary(Runtime.java:367)
       at java.lang.System.loadLibrary(System.java:1076)
       at org.puredata.core.PdBase.(PdBase.java)
       at org.puredata.android.io.PdAudio.isRunning(PdAudio.java:122)
       at org.puredata.android.io.PdAudio.initAudio(PdAudio.java:57)

In my apk, I have lib/x86, lib/armeabi, and lib/armeabi_v7a. libpd.so is available at these 3 locations as well.

Now I am not sure what to do. I wonder if this is bug in this device's android build. Anyone saw similar issues with this or other devices?

luizmello commented 6 years ago

Hi, according to this post https://android-developers.googleblog.com/2017/12/improving-app-security-and-performance.html

In August 2019, Play will require that new apps and app updates with native libraries provide 64-bit versions in addition to their 32-bit versions.

There is a way to build a 64-bit version for pd-for-android?

Thank you