realm / realm-java

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

Realm crashes, can't load unrelated native lib #3430

Closed Chris59160 closed 8 years ago

Chris59160 commented 8 years ago

Hello,

I have a problem when I apply the realm plug-in to my project. Suddenly it can't find the libraries in jniLibs any more.

Goal

Use Realm Android, in a project using EPos2 sdk from Epson for printer.

Expected Results

It doesn't crash the app when I add "apply plugin: 'realm-android'" at the top of my module build.gradle I have tried not using instant run. Still same result

Actual Results

The app crashes straight away on launch, claiming it can't find the libepos2.so in the jniLibs folder. If I remove "apply plugin: 'realm-android'" from my build.gradle, it works like a charm.

Steps & Code to Reproduce

I have taken the sample code from Epson, added library in the build.gradle one by one to check what is wrong. The issue comes as soon as I apply the realm plug-in

Code Sample

link to dropbox : https://www.dropbox.com/s/llqb0aosvigbdq5/ePOS2_Printer.zip?dl=0 Sorry it's a 60Mb zip.

Version of Realm and tooling

Realm version(s): ? 1.2.0

Android Studio version: ? 2.1.3

Which Android version and device: ? HTC M8, running Android 6.0

beeender commented 8 years ago

It is because of the epos2 only have armeabi so file. See https://realm.io/docs/java/latest/#couldnt-load-librealm-jniso

Chris59160 commented 8 years ago

Cheers beeender.

Still crashing...excuse me for asking, but before replying, did you actually download the project, got the crash, tried your solution and got it working ?

I tried to do: Added to defaultConfig in build.gradle of the module ndk { abiFilters "armeabi-v7a" }

and
packagingOptions { exclude 'lib/arm64-v8a/librealm-jni.so' }

But no luck

beeender commented 8 years ago

No, i didn't try my solution, but I did download the project, and saw it only has the armeabi so file. And the similar problem happened lot of times already.

And the solution to this problem is slightly different from the doc i shared, that one is caused by the missing arm64 so file.

So, for your problem, you have to exclude all other so files like:

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

After build, you might want to verify the result by decompress the apk file and check if it is only lib/armeabi left there, otherwise something is still wrong.

Do a CLEAN before build.

Chris59160 commented 8 years ago

Thanks, Let me try that, I'll come back to you

Chris59160 commented 8 years ago

Ok, it almost worked. I needed to add an extra exclude:

exclude "lib/x86_64/librealm-jni.so"

And now it's fine :-)

Thanks for the help

maxi182 commented 7 years ago

Hey guys, i am having this issue as well, libepos2.so can not be found and I am using realm in the project. The poblem i have, if i do that exclude.. realm is not going to be able to initialise..

Chris59160 commented 7 years ago

Hi maxi182, do you have any other library included the same way ? My issue was due to having to include other C libraries.