realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.45k stars 1.75k forks source link

Epson android jni library having conflict with Realm #5046

Closed maxi182 closed 7 years ago

maxi182 commented 7 years ago

Goal

I am building an Android app, using Realm v3.3.1, my app must include an Epson library( ePOS_SDK_Android_v2.5.2.zip) which has a JNI lib included to allow the device print via bluetooth

Expected Results

I expect to have no conflicts with the epson library that aparently does not support 64bit architectures.

Actual Results

Trying to call the epson library makes me get "couldn't find "libepos2.so" , as it only support armbi 32bit as far as i know, and realm is loading in 64 from the begining of the app, but I also tryed to remove the 64bit libs from realm to make it load everything in 32bit, but is not working. Here below is what i tryed.

If i exclude the following .so files

    packagingOptions {
        exclude "lib/arm64-v8a/librealm-jni.so"
        exclude "lib/armeabi-v7a/librealm-jni.so"
        exclude "lib/mips/librealm-jni.so"
        exclude "lib/x86/librealm-jni.so"
        exclude "lib/x86_64/librealm-jni.so"
    }

I get:

07-29 23:21:38.837 13542-13542/com.epson.epos2_printer E/AndroidRuntime: FATAL EXCEPTION: main Process: com.epson.epos2_printer, PID: 13542 java.lang.RuntimeException: Unable to create application com.epson.epos2_printer.eposApplication: com.getkeepsafe.relinker.MissingLibraryException: lib/armeabi/librealm-jni.so at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5408) at android.app.ActivityThread.-wrap2(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1546) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6121) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) Caused by: com.getkeepsafe.relinker.MissingLibraryException: lib/armeabi/librealm-jni.so at com.getkeepsafe.relinker.ApkLibraryInstaller.installLibrary(ApkLibraryInstaller.java:85) at com.getkeepsafe.relinker.ReLinkerInstance.loadLibraryInternal(ReLinkerInstance.java:180) at com.getkeepsafe.relinker.ReLinkerInstance.loadLibrary(ReLinkerInstance.java:136) at com.getkeepsafe.relinker.ReLinker.loadLibrary(ReLinker.java:70) at com.getkeepsafe.relinker.ReLinker.loadLibrary(ReLinker.java:57) at io.realm.internal.RealmCore.loadLibrary(RealmCore.java:60) at io.realm.Realm.init(Realm.java:197) at com.epson.epos2_printer.eposApplication.onCreate(eposApplication.java:18) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5405) at android.app.ActivityThread.-wrap2(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1546)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:154)  at android.app.ActivityThread.main(ActivityThread.java:6121)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) 

so, if i haven't exclued lib/armeabi/librealm-jni.so , why i am geting these?

And if i do not exclude any of the .so from Realm i will get: 07-29 23:41:54.649 15429-15429/com.epson.epos2_printer E/AndroidRuntime: FATAL EXCEPTION: main Process: com.epson.epos2_printer, PID: 15429 java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.epson.epos2_printer-1/base.apk"],nativeLibraryDirectories=[/data/app/com.epson.epos2_printer-1/lib/arm64, /system/fake-libs64, /data/app/com.epson.epos2_printer-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]] couldn't find "libepos2.so" at java.lang.Runtime.loadLibrary0(Runtime.java:984) at java.lang.System.loadLibrary(System.java:1562) at com.epson.epos2.Log.<clinit>(Log.java:12) at com.epson.epos2.Log.setLogSettings(Log.java:51) at com.epson.epos2_printer.MainActivity.onCreate(MainActivity.java:95) at android.app.Activity.performCreate(Activity.java:6682) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6121) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

Version of Realm and tooling

Realm version(s): v3.3.1

Android Studio version: 2.3.3

Which Android version and device: Nexus 5x N

nhachicha commented 7 years ago

I think Epson .so is an armeabi which force the system to look for armeabi ABI which is not supported anymore in Realm.

I'm not sure how you're loading the Epson SDK, try to load the Realm SDK first and see if you get the same error stack.

maxi182 commented 7 years ago

Thanks for your response @nhachicha. Acually, after writing this post, I found that i have to downgrade to Realm 1.2.0 as its the last one supporting armeabi, something related about what you are saying, and yes, seems that the conflict is no longer happening.. The thing is I am having a new issue now as I had to downgrade from 3.3.1 to 1.2.0. I am getting the INVALID FORMAT OF REALM FILE, when i try to call Realm.getDefaultInstance(); java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mcba.comandaclient/com.mcba.comandaclient.ui.MainActivity}: java.lang.IllegalArgumentException: Illegal Argument: Invalid format of Realm file.

Any insights on this?

Thanks

Zhuinden commented 7 years ago

The Realm file format upgrade in 2.0.0 and 3.1.0 are not backwards compatible. You'd need to catch this exception and delete the existing database.

maxi182 commented 7 years ago

Hi @Zhuinden, I have already deleted the app and reinstalled from scratch, and still happening, what do you mean with catch that exception? if I add a Try catch to Realm.getDefaultInstance() which returns my Realm object, it will be null..

nhachicha commented 7 years ago

@maxi182 Are you shipping a Realm with the APK that might be created with the new format? How are you deleting the app using adb uninstall?

maxi182 commented 7 years ago

Hi @nhachicha , I actually tryed deleting the app with ADB idea (that plugin) and manually as well from the device

nhachicha commented 7 years ago

@maxi182 is it possible to share the latest APK to try to reproduce?

maxi182 commented 7 years ago

Hey Nabil, sure, i just sent it to help@realm.io Thanks!

nhachicha commented 7 years ago

@maxi182 I run the app on armv7 Android 6.0 emulator and it didn't crash

screen shot 2017-08-01 at 00 29 18
maxi182 commented 7 years ago

Yep, I had to restart the device after unistall the app, for some reason the realm file was cached or somethig. Thanks for your great support!