jeremyb
jeremyb

Reputation: 492

TensorFlow + AndroidScanner - couldn't find "libopencv_java3.so"

I'm having a problem with combining Tensorflow and AndroidScanner.

I use Tensorflow to display an overlay over the camera feed. I take a picture with the camera, and then send it to a server. It works.

Now I imported the AndroidScannerDemo, I want to use the taken picture and crop/transform it with the newly imported module. It crashes. When I open the ScanActivity (from the AndroidScannerDemo), it tries to load opencv, and never succeeds. The error message is as follows:

FATAL EXCEPTION: main

    Process: fr.pacifica.insurancechat.debug, PID: 2139
    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/fr.pacifica.insurancechat.debug-OI_d1EANbiczpZEwAHYdkw==/base.apk"],nativeLibraryDirectories=[/data/app/fr.pacifica.insurancechat.debug-OI_d1EANbiczpZEwAHYdkw==/lib/arm64, /data/app/fr.pacifica.insurancechat.debug-OI_d1EANbiczpZEwAHYdkw==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]] couldn't find "libopencv_java3.so"
    at java.lang.Runtime.loadLibrary0(Runtime.java:1011)
    at java.lang.System.loadLibrary(System.java:1657)
    at com.scanlibrary.ScanActivity.(ScanActivity.java:125)
    at java.lang.Class.newInstance(Native Method)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1190)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2837)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3046)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6809)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

When I delete TensorFlow references from gradle/code, the imported module works just fine.

Upvotes: 3

Views: 2794

Answers (2)

Javier Diaz
Javier Diaz

Reputation: 119

I had the same problem with some mobiles (64 bits processor)

Here is the libs you need for every single arquitecture. You can download it and import manually.

https://github.com/jhansireddy/AndroidScannerDemo/tree/2cd23d3d362d0a6248cf489a79ebc4ba2c425c60/ScanDemoExample/scanlibrary/src/main/libs

Upvotes: 0

Alex Cohn
Alex Cohn

Reputation: 57203

The project you imported, only builds 32-bit versions of libScanner.so, and therefore only uses the 32-bit versions of libopencv_java3.so. In the short run, you can keep that, only set

android {
  defaultConfig {
    ndk {
      abiFilters 'armeabi-v7a'
    }
  }
}

This will cause your APK run in 32-bit mode on arm64 devices.

In the long run, you should update the Scanner library to build in 64-bit, too. This may have a significant performance gain.

from August 2019, 64-bit support is required for all apps in Play Store

Upvotes: 5

Related Questions