Android 0.64.0 - Unable to load library 'snips_megazord'

Hi,

Upgrading to 0.64.0 (from 0.63.3) results in the following error:

java.lang.UnsatisfiedLinkError: Unable to load library 'snips_megazord': Native library (android-arm/libsnips_megazord.so) not found in resource path (.)

Is this a known issue? Or do we need to update something else?

(We’ve double-checked the steps in https://docs.snips.ai/getting-started/quick-start-android - including the packagingOptions)

Also, if this can’t easily be fixed, is there a way to train models for older versions through the console? Downgrading back to 0.63.3 but using a newer model gives:

Mismatched model version: model is 0.20.0 but runner is 0.19.0

Thanks

Hi @david115 !

did you add theses packaging options

packagingOptions {
        exclude 'lib/armeabi/'
        exclude 'lib/mips/'
        exclude 'lib/mips64/*'
}

to your build.gradle ?

Thanks for the reply. Indeed we have those packaging options set, from the quick start guide.

do you (or some of you deps) package some native libs ? what arch is the phone you’re seing this on ?

We’re testing on an armeabi-v7a device. It’s a pretty bare-bones React Native Android project.

I should also mention that we’ve tried running the official example project (https://github.com/snipsco/snips-platform-android-demo) which gives the same error, so it shouldn’t be related to our implementation. Running that on an armeabi-v7a device should hopefully allow you to reproduce.

could you extract your generated APK a run the tree command on the lib folder inside it ?

here’s what the output looks like on my end

$ tree lib
lib
β”œβ”€β”€ arm64-v8a
β”‚   β”œβ”€β”€ libc++_shared.so
β”‚   β”œβ”€β”€ libjnidispatch.so
β”‚   β”œβ”€β”€ libsnips_kaldi.so
β”‚   └── libsnips_megazord.so
β”œβ”€β”€ armeabi-v7a
β”‚   β”œβ”€β”€ libc++_shared.so
β”‚   β”œβ”€β”€ libjnidispatch.so
β”‚   β”œβ”€β”€ libsnips_kaldi.so
β”‚   └── libsnips_megazord.so
β”œβ”€β”€ x86
β”‚   β”œβ”€β”€ libc++_shared.so
β”‚   β”œβ”€β”€ libjnidispatch.so
β”‚   β”œβ”€β”€ libsnips_kaldi.so
β”‚   └── libsnips_megazord.so
└── x86_64
    β”œβ”€β”€ libc++_shared.so
    β”œβ”€β”€ libjnidispatch.so
    β”œβ”€β”€ libsnips_kaldi.so
    └── libsnips_megazord.so

4 directories, 16 files

I’m guessing react will add other files

Think our messages just crossed! As mentioned, the official Android demo (https://github.com/snipsco/snips-platform-android-demo) has the same issue, so shouldn’t be related to our implementation/React Native (and 0.63.3 works).

The output of the example APK is the same as yours:

lib
β”œβ”€β”€ arm64-v8a
β”‚   β”œβ”€β”€ libc++_shared.so
β”‚   β”œβ”€β”€ libjnidispatch.so
β”‚   β”œβ”€β”€ libsnips_kaldi.so
β”‚   └── libsnips_megazord.so
β”œβ”€β”€ armeabi-v7a
β”‚   β”œβ”€β”€ libc++_shared.so
β”‚   β”œβ”€β”€ libjnidispatch.so
β”‚   β”œβ”€β”€ libsnips_kaldi.so
β”‚   └── libsnips_megazord.so
β”œβ”€β”€ x86
β”‚   β”œβ”€β”€ libc++_shared.so
β”‚   β”œβ”€β”€ libjnidispatch.so
β”‚   β”œβ”€β”€ libsnips_kaldi.so
β”‚   └── libsnips_megazord.so
└── x86_64
    β”œβ”€β”€ libc++_shared.so
    β”œβ”€β”€ libjnidispatch.so
    β”œβ”€β”€ libsnips_kaldi.so
    └── libsnips_megazord.so

4 directories, 16 files

I just tried again the demo on my OnePlus one and it works like a charm… which android version are you using ?

This is on Android 7.1.2.

could you set com.sun.jna.Native.DEBUG_LOAD = true in the onCreate of you application class (this needs to be here as the platform is loaded in a separate process) and send the logs ?

Sorry for the delay. Please see below:

10-09 17:04:03.756 22750 22780 D MainActivity: starting audio streaming
10-09 17:04:03.761 22750 22780 D MainActivity: minBufferSizeInBytes: 1280
10-09 17:04:03.790  1833 22782 I AudioFlinger: AudioFlinger's thread 0xb099e480 ready to run
10-09 17:04:03.800  1833  2074 I SoundTriggerHwService::Module: void android::SoundTriggerHwService::Module::onCallbackEvent(const sp<android::SoundTriggerHwService::CallbackEvent> &) mClient == 0
10-09 17:04:03.801  1833 22782 E audio_route: unable to find path 'set-capture-format-default'
10-09 17:04:03.801  1833 22782 D audio_hw_primary: enable_snd_device: snd_device(28: handset-mic)
10-09 17:04:03.809  1833 22782 D audio_hw_primary: enable_audio_route: usecase(8) apply and update mixer path: audio-record
10-09 17:04:03.916 22750 22750 I TextToSpeech: Sucessfully bound to com.google.android.tts
10-09 17:04:03.917 22750 22750 I SnipsPlatform: Connecting to remote Snips processing service
10-09 17:04:03.933  2238  3516 I ActivityManager: Start proc 22783:ai.snips.snipsdemo:snipsProcessingService/u0a113 for service ai.snips.snipsdemo/ai.snips.platform.SnipsProcessingService
10-09 17:04:03.940 22783 22783 I art     : Late-enabling -Xcheck:jni
10-09 17:04:03.947 12185 12185 I TTS     : Creating Google TTS service, version 3.15.18.200023596
10-09 17:04:03.963 12185 22797 I TTS     : Initializing en-gb-x-fis-lstm-embedded from disk
10-09 17:04:03.987 22750 22750 I TextToSpeech: Connected to ComponentInfo{com.google.android.tts/com.google.android.tts.service.GoogleTTSService}
10-09 17:04:04.011 12185 12197 I TTS     : For default lang en-gb is name en-GB-language (en-gb-x-fis-server)
10-09 17:04:04.011 22750 22800 I TextToSpeech: Set up connection to ComponentInfo{com.google.android.tts/com.google.android.tts.service.GoogleTTSService}
10-09 17:04:04.016 22783 22783 I SnipsDemoApp: in the snips process
10-09 17:04:04.020 22750 22750 I SnipsPlatform: Snips processing service connected, starting the platform
10-09 17:04:04.040 22783 22783 I SnipsPlatform: registering client 8fbe45ed-8aeb-48aa-82ee-f82e551efab5
10-09 17:04:04.050 22783 22783 I System.out: Looking for library 'snips_megazord'
10-09 17:04:04.050 22783 22783 I System.out: Adding paths from jna.library.path: null
10-09 17:04:04.050 22783 22783 I System.out: Trying libsnips_megazord.so
10-09 17:04:04.052 22783 22783 W linker  : /data/app/ai.snips.snipsdemo-1/lib/arm/libsnips_kaldi.so: unused DT entry: type 0x7ffffffd arg 0x1f6a1e
10-09 17:04:04.140 22783 22783 I System.out: Adding system paths: []
10-09 17:04:04.140 22783 22783 I System.out: Trying libsnips_megazord.so
10-09 17:04:04.141 22783 22783 W linker  : /data/app/ai.snips.snipsdemo-1/lib/arm/libsnips_kaldi.so: unused DT entry: type 0x7ffffffd arg 0x1f6a1e
10-09 17:04:04.219 22783 22783 I System.out: Preload (via System.loadLibrary) snips_megazord
10-09 17:04:04.220 22783 22783 W linker  : /data/app/ai.snips.snipsdemo-1/lib/arm/libsnips_kaldi.so: unused DT entry: type 0x7ffffffd arg 0x1f6a1e
10-09 17:04:04.295 22783 22783 I System.out: Looking in classpath from dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/ai.snips.snipsdemo-1/base.apk"],nativeLibraryDirectories=[/data/app/ai.snips.snipsdemo-1/lib/arm, /data/app/ai.snips.snipsdemo-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]] for snips_megazord
10-09 17:04:04.304 22783 22783 D AndroidRuntime: Shutting down VM
10-09 17:04:04.305 22783 22783 E AndroidRuntime: FATAL EXCEPTION: main
10-09 17:04:04.305 22783 22783 E AndroidRuntime: Process: ai.snips.snipsdemo:snipsProcessingService, PID: 22783
10-09 17:04:04.305 22783 22783 E AndroidRuntime: java.lang.UnsatisfiedLinkError: Unable to load library 'snips_megazord': Native library (android-arm/libsnips_megazord.so) not found in resource path (.)
10-09 17:04:04.305 22783 22783 E AndroidRuntime: 	at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:303)
10-09 17:04:04.305 22783 22783 E AndroidRuntime: 	at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:427)
10-09 17:04:04.305 22783 22783 E AndroidRuntime: 	at com.sun.jna.Library$Handler.<init>(Library.java:179)
10-09 17:04:04.305 22783 22783 E AndroidRuntime: 	at com.sun.jna.Native.loadLibrary(Native.java:569)
10-09 17:04:04.305 22783 22783 E AndroidRuntime: 	at com.sun.jna.Native.loadLibrary(Native.java:544)
10-09 17:04:04.305 22783 22783 E AndroidRuntime: 	at ai.snips.platform.Megazord$MegazordLibrary$Companion.<clinit>(Megazord.kt:402)
10-09 17:04:04.305 22783 22783 E AndroidRuntime: 	at ai.snips.platform.Megazord$MegazordLibrary.<clinit>(Megazord.kt)
10-09 17:04:04.305 22783 22783 E AndroidRuntime: 	at ai.snips.platform.Megazord$Companion.build(Megazord.kt:62)
10-09 17:04:04.305 22783 22783 E AndroidRuntime: 	at ai.snips.platform.SnipsProcessingService.initMegazord(SnipsProcessingService.kt:167)
10-09 17:04:04.305 22783 22783 E AndroidRuntime: 	at ai.snips.platform.SnipsProcessingService.registerClient(SnipsProcessingService.kt:116)
10-09 17:04:04.305 22783 22783 E AndroidRuntime: 	at ai.snips.platform.SnipsProcessingService.access$registerClient(SnipsProcessingService.kt:25)
10-09 17:04:04.305 22783 22783 E AndroidRuntime: 	at ai.snips.platform.SnipsProcessingService$MessageHandler.handleMessage(SnipsProcessingService.kt:95)
10-09 17:04:04.305 22783 22783 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:102)
10-09 17:04:04.305 22783 22783 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:154)
10-09 17:04:04.305 22783 22783 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:6171)
10-09 17:04:04.305 22783 22783 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
10-09 17:04:04.305 22783 22783 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:891)
10-09 17:04:04.305 22783 22783 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:781)

Hum this is weird.

JNA seems to indeed find the lib, the warning we see about libsnips_kaldi is something that can only be seen when loading libsnips_kaldi.so which is a dependency of the main libsnips_megazord.so library, this means the system finds the libs but fails to load them somehow.

Just to be sure, could you try and uninstall completely the app and reinstall it using the command line ?

$ adb uninstall ai.snips.snipsdemo
$ ./gradlew installDebug
$ adb shell am start -n ai.snips.snipsdemo/.MainActivity

should do the trick

I’ve seen some problems when using androidstudio and especially instant run to deploy the app

Weird indeed! We’ve not been running either through Android studio, but via ./gradlew installDebug.

Just to be sure, I’ve run the commands you suggested on the demo app - but still the same problem.

let’s try to load the so by ourselves and see if we get an error that is swallowed by JNA

System.out.println("trying to load the so");
System.loadLibrary("snips_megazord");
System.out.println("lib loaded");

Please see below, I put this immediately after setting com.sun.jna.Native.DEBUG_LOAD = true in DemoApplication::onCreate. I wrapped it in a try/finally to print β€œlib failed” immediately after trying to load. There was a stack trace after this though, which I’ve left in.

10-10 12:53:24.915 20908 20908 I System.out: trying to load the so
10-10 12:53:24.917 20908 20908 W linker  : /data/app/ai.snips.snipsdemo-2/lib/arm/libsnips_kaldi.so: unused DT entry: type 0x7ffffffd arg 0x1f6a1e
10-10 12:53:24.987 20908 20908 I System.out: lib failed
10-10 12:53:24.987 20908 20908 D AndroidRuntime: Shutting down VM
10-10 12:53:24.988 20908 20908 E AndroidRuntime: FATAL EXCEPTION: main
10-10 12:53:24.988 20908 20908 E AndroidRuntime: Process: ai.snips.snipsdemo, PID: 20908
10-10 12:53:24.988 20908 20908 E AndroidRuntime: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__emutls_get_address" referenced by "/data/app/ai.snips.snipsdemo-2/lib/arm/libsnips_kaldi.so"...
10-10 12:53:24.988 20908 20908 E AndroidRuntime: 	at java.lang.Runtime.loadLibrary0(Runtime.java:989)
10-10 12:53:24.988 20908 20908 E AndroidRuntime: 	at java.lang.System.loadLibrary(System.java:1562)
10-10 12:53:24.988 20908 20908 E AndroidRuntime: 	at ai.snips.snipsdemo.DemoApplication.onCreate(DemoApplication.java:22)
10-10 12:53:24.988 20908 20908 E AndroidRuntime: 	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
10-10 12:53:24.988 20908 20908 E AndroidRuntime: 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5455)
10-10 12:53:24.988 20908 20908 E AndroidRuntime: 	at android.app.ActivityThread.-wrap2(ActivityThread.java)
10-10 12:53:24.988 20908 20908 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1557)
10-10 12:53:24.988 20908 20908 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:102)
10-10 12:53:24.988 20908 20908 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:154)
10-10 12:53:24.988 20908 20908 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:6171)
10-10 12:53:24.988 20908 20908 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
10-10 12:53:24.988 20908 20908 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:891)
10-10 12:53:24.988 20908 20908 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:781)
10-10 12:53:24.990  2311  3554 W ActivityManager:   Force finishing activity ai.snips.snipsdemo/.MainActivity

thanks! this is indeed way better as error goes! seems like a known issue

we did downgrade the NDK used to build libsnips_megazord.so to 16 prior to releasing 1.3 (we had some compatibility issues in some edge cases with later NDKs), I’m currently investigating if the libc++_shared.so we ship is the right one. Will get back to you

Ok, so this is indeed a problem on our side, we don’t ship the correct libc++_shared.so for armv7 (the other arch are ok), the one we ship comes from the ndk15b.

We’ll ship a patched version soon (as in the next few weeks) in the mean time you should be able to fix this by adding the correct .so to your app build:

  • get the ndk16b libc++_shared.so lib (located at android-ndk-r16b/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a) and put it in src/main/lib/armeabi-v7a in your project (or get it here and rename it properly)
  • add the following to the android section of your build.gradle
    sourceSets {
        main.jniLibs.srcDirs += "src/main/lib"
    }

and it shoud work

Thanks for letting me know, I’ll keep an eye out for a new build. For now, the workaround seems to work fine.

1 Like