gradle project dependency with MultiDex - android

I have two .aar files that I need to add to my project as dependencies. I imported the projects and did the following and it worked just fine.
dependencies {
compile project(':zoomcommonlib')
compile project(':zoomsdk')
}
However, I have added many other libraries and I had to use MultiDex library to support apps over 64K methods
dependencies {
compile 'com.android.support:multidex:1.0.1'
compile project(':zoomcommonlib')
compile project(':zoomsdk')
compile 'com.google.android.gms:play-services-maps:10.2.0'
compile 'com.google.android.gms:play-services-location:10.2.0'
.....
}
Yes, MultiDex is properly setup because I can build the application and run it with no problem.
The problem: When I try to utilize those specific projects, application crashes. Following Log:
18790-18790/com.mypackage.name E/UncaughtException: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.mypackage.name-1/base.apk", zip file "/data/app/com.mypackage.name-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.mypackage.name-1/lib/arm64, /data/app/com.mypackage.name-1/base.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_dependencies_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_0_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_1_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_2_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_3_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_4_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_5_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_6_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_7_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_8_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_9_apk.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]] couldn't find "libzoom_stlport.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:984)
at java.lang.System.loadLibrary(System.java:1530)
at com.zipow.cmmlib.AppContext.<clinit>(AppContext.java:31)
at com.zipow.cmmlib.AppContext.initialize(AppContext.java:64)
at us.zoom.sdk.ZoomSDK.initialize(ZoomSDK.java:225)
at us.zoom.sdk.ZoomSDK.initialize(ZoomSDK.java:184)
at com.mypackage.name.SectionListActivity.getInitializedZoomSDK(SectionListActivity.java:857)
at com.mypackage.name.SectionListActivity.access$1500(SectionListActivity.java:88)
at com.mypackage.name.SectionListActivity$8.onClick(SectionListActivity.java:812)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
18790-18899/com.mypackage.name D/FA: Logging event (FE): _ae, Bundle[{_o=crash, _sc=SectionListActivity, _si=7450316610930895524, timestamp=1488996958198, fatal=1}]
18790-18899/com.mypackage.name V/FA: Using measurement service
18790-18899/com.mypackage.name V/FA: Connecting to remote service
--------- beginning of crash
18790-18790/com.mypackage.name E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mypackage.name, PID: 18790
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.mypackage.name-1/base.apk", zip file "/data/app/com.mypackage.name-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.mypackage.name-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.mypackage.name-1/lib/arm64, /data/app/com.mypackage.name-1/base.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_dependencies_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_0_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_1_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_2_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_3_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_4_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_5_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_6_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_7_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_8_apk.apk!/lib/arm64-v8a, /data/app/com.mypackage.name-1/split_lib_slice_9_apk.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]] couldn't find "libzoom_stlport.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:984)
at java.lang.System.loadLibrary(System.java:1530)
at com.zipow.cmmlib.AppContext.<clinit>(AppContext.java:31)
at com.zipow.cmmlib.AppContext.initialize(AppContext.java:64)
at us.zoom.sdk.ZoomSDK.initialize(ZoomSDK.java:225)
at us.zoom.sdk.ZoomSDK.initialize(ZoomSDK.java:184)
at com.mypackage.name.SectionListActivity.getInitializedZoomSDK(SectionListActivity.java:857)
at com.mypackage.name.SectionListActivity.access$1500(SectionListActivity.java:88)
at com.mypackage.name.SectionListActivity$8.onClick(SectionListActivity.java:812)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
From my understanding, those project dependencies are not properly getting added with MultiDex enabled. Is there some configuration that I am missing for project dependencies?
I've also tried the following in my build.gradle file.
dexOptions {
preDexLibraries = false
}
It seems to have no effect on it. It crashes each time.

The ZoomSDK you have doesn't support 64bit Android, unfortunately. In the mean time, you need to disable the use of 64bit libraries in your app and only support the mentioned framework so it builds in 32bit mode.
Add the following to the build.gradle of the main module of your app:
android {
defaultConfig {
ndk {
abiFilters "armeabi-v7a"
}
}
}
From the Zoom forum:
We support only 32 bit libs now. To work on 64 bit devices, you should
not use other 64 bit libs ( from other projects or other third party
SDK). Android OS can support 32 bit libs on 64 bit devices if you
don't have other 64 bit libs in the project

For x86, it can be supported via Intel ARM binary translator
(Houdini). But your app should not contain other x86 targeted native
binaries.
In order for the app to run on x86, all the binary files in your app should target on ARM, binary translator will translate them to
support x86.
If your app contains other binary files that target on x86, you should delete those files to remain only ARM targets. Because on x86
devices, if an app have binary files target on x86, it also should
have the file that target on ARM. Because Zoom Android SDK does not
contains any x86 binaries, so other files also can't have binaries
that target on x86 in order for the SDK to run.
The ARM binary translator works at run time, not at compile time.
You only need to add following to main gradle file
android {
defaultConfig {
ndk {
abiFilters "armeabi-v7a"
}
}
}
and in gradle.properties file add the following line
android.useDeprecatedNdk = true

Related

E/Unity: Unable to find main

I am using Unity in combination with a custom NDK-Library, inside my app.
My problem is that if I try to start the Activity hosting Unity, the process always crashes with the message:
E/Unity: Unable to find main
and a alertBox from Unity:
Title:Failure to initialize!
Message: Your hardware doesn't support this Application
After some trying arround, I got the solution that I have to add the following into my gradle File:
android{
...
defaultConfig{
...
ndk {
abiFilters 'armeabi-v7a', 'x86'
}
}
...
}
after doing this Unity runs without Errors, but when I start an Activity housing my own NDK-Library it crashes with the Error.
Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/de.biosign.daimlerhrv-2/base.apk", zip file "/data/app/de.biosign.daimlerhrv-2/split_lib_dependencies_apk.apk", zip file "/data/app/de.biosign.daimlerhrv-2/split_lib_slice_0_apk.apk", zip file "/data/app/de.biosign.daimlerhrv-2/split_lib_slice_1_apk.apk", zip file "/data/app/de.biosign.daimlerhrv-2/split_lib_slice_2_apk.apk", zip file "/data/app/de.biosign.daimlerhrv-2/split_lib_slice_3_apk.apk", zip file "/data/app/de.biosign.daimlerhrv-2/split_lib_slice_4_apk.apk", zip file "/data/app/de.biosign.daimlerhrv-2/split_lib_slice_5_apk.apk", zip file "/data/app/de.biosign.daimlerhrv-2/split_lib_slice_6_apk.apk", zip file "/data/app/de.biosign.daimlerhrv-2/split_lib_slice_7_apk.apk", zip file "/data/app/de.biosign.daimlerhrv-2/split_lib_slice_8_apk.apk", zip file "/data/app/de.biosign.daimlerhrv-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/de.biosign.daimlerhrv-2/lib/arm64, /system/lib64, /vendor/lib64, /system/vendor/lib64]]] couldn't find "libMyLib.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:972)
at java.lang.System.loadLibrary(System.java:1530)
at de.biosign.sessioncomponents.session.RunningSession.<clinit>(RunningSession.java:34)
at de.biosign.mvc.session.sessionController.SessionController.<init>(SessionController.java:63)
at de.biosign.biofeedbackunity.BiofeedbackUnity.onCreate(BiofeedbackUnity.java:109)
at android.app.Activity.performCreate(Activity.java:6666)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Has anyone got a solution for this problem and can give me a Hint.
Thanks
According to your error logs
Caused by: java.lang.UnsatisfiedLinkError: ...... /system/lib64, /vendor/lib64, /system/vendor/lib64
It looks your device is 64-bit. But your abiFilters 'armeabi-v7a', 'x86' is only for 32-bit.
So, the possible solution to your problems may be as below adding 64-bit ABIs into the abiFilters:
abiFilters 'armeabi-v7a', 'x86', 'arm64-v8a', 'x86_64'
Cross check:
Android NDK - Using libraries compiled with a different API level
How do we identify libraries build with NDK is 64-bit supported?
The solution for me was to add the following to my Android.mk:
(See also at https://developer.android.com/ndk/guides/android_mk)
TARGET_ARCH : armeabi-v7a x86
so my libs became, generated for this architecture, it runs again beside Unity,
According to some posts newer Versions of above 2017.4 Unity already support 64 bits, but for my work am using 5.6, so can use this.
For others using 2017.4 or above there is the link:
https://developer.android.com/distribute/best-practices/develop/64-bit#unity_developers

Issue with EPSON, couldn't find "libepos2.so"

EPSON network printer was working perfect until I integrated mSwipe(Card Swiper) with my Android App.
After integration now mSwipe working perfectly but everything about EPSON is crashing.
libepos2.so is there in src/main/jniLibs/armeabi/libepos2.so but still it says couldn't find.
log below:
FATAL EXCEPTION: main
Process: com.intuition.dine.ivepos, PID: 10908
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.intuition.dine.ivepos-1/base.apk"],nativeLibraryDirectories=[/data/app/com.intuition.dine.ivepos-1/lib/arm, /data/app/com.intuition.dine.ivepos-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]] couldn't find "libepos2.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:972)
at java.lang.System.loadLibrary(System.java:1567)
at com.epson.epos2.discovery.Discovery.<clinit>(Discovery.java:20)
at com.epson.epos2.discovery.Discovery.start(Discovery.java)
at com.intuition.dine.ivepos.SearchIPActivity.onCreate(SearchIPActivity.java:191)
at android.app.Activity.performCreate(Activity.java:6955)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Any help would be appreciated.
Solved : I have some more .so files which are inside app/libs/armeabi.
So, I moved them to app/src/main/jniLibs (Just like below Image)
Also, below code in app level Gradle inside defaultconfig{}
ndk {
abiFilters "armeabi"
}
And
android{
splits {
abi {
enable true
reset()
universalApk true
}
}
}
This worked like charm.
I tried everything in the answers here (and from other questions on stackoverflow), but the only fix for me was making a folder in app/src/main/jniLibs called armeabi-v7a and copying the so files from armeabi to it.
Add this to your app level gradle file, clean, rebuild and try again.
android {
//Other stuff here
splits {
abi {
enable true
reset()
universalApk true
}
}
}

UnsatisfiedLinkError: No implementation found for void com.mopo.audiofingerprinter.tageditor.ACRCloudExtrTool.native_init()

I cloned this project and and copied the .so files to my project's jniLibs folder.
After that, it looked like this:
However, when I tried using the library it throws:
09-18 10:22:53.861 18439-19193/com.mopo.audiofingerprinter W/linker: libACRCloudExtrTool.so: unused DT entry: type 0x6ffffffe arg 0x4718
09-18 10:22:53.861 18439-19193/com.mopo.audiofingerprinter W/linker: libACRCloudExtrTool.so: unused DT entry: type 0x6fffffff arg 0x2
09-18 10:22:53.871 18439-19193/com.mopo.audiofingerprinter E/art: No implementation found for void com.mopo.audiofingerprinter.tageditor.ACRCloudExtrTool.native_init() (tried Java_com_mopo_audiofingerprinter_tageditor_ACRCloudExtrTool_native_1init and Java_com_mopo_audiofingerprinter_tageditor_ACRCloudExtrTool_native_1init__)
09-18 10:22:53.881 18439-19193/com.mopo.audiofingerprinter E/UncaughtException: java.lang.UnsatisfiedLinkError: No implementation found for void com.mopo.audiofingerprinter.tageditor.ACRCloudExtrTool.native_init() (tried Java_com_mopo_audiofingerprinter_tageditor_ACRCloudExtrTool_native_1init and Java_com_mopo_audiofingerprinter_tageditor_ACRCloudExtrTool_native_1init__)
at com.mopo.audiofingerprinter.tageditor.ACRCloudExtrTool.native_init(Native Method)
at com.mopo.audiofingerprinter.tageditor.ACRCloudExtrTool.<clinit>(ACRCloudExtrTool.java:57)
at com.mopo.audiofingerprinter.tageditor.ACRCloudExtrTool.createFingerprintByFile(ACRCloudExtrTool.java:0)
at com.mopo.audiofingerprinter.tageditor.ACRCloudRecognizer.recognizeByFile(ACRCloudRecognizer.java:129)
at com.mopo.audiofingerprinter.tageditor.TestActivity$RecThread.run(TestActivity.java:84)
09-18 10:22:54.132 18439-19193/com.mopo.audiofingerprinter E/AndroidRuntime: FATAL EXCEPTION: Thread-51298
Process: com.mopo.audiofingerprinter, PID: 18439
java.lang.UnsatisfiedLinkError: No implementation found for void com.mopo.audiofingerprinter.tageditor.ACRCloudExtrTool.native_init() (tried Java_com_mopo_audiofingerprinter_tageditor_ACRCloudExtrTool_native_1init and Java_com_mopo_audiofingerprinter_tageditor_ACRCloudExtrTool_native_1init__)
at com.mopo.audiofingerprinter.tageditor.ACRCloudExtrTool.native_init(Native Method)
at com.mopo.audiofingerprinter.tageditor.ACRCloudExtrTool.<clinit>(ACRCloudExtrTool.java:57)
at com.mopo.audiofingerprinter.tageditor.ACRCloudExtrTool.createFingerprintByFile(ACRCloudExtrTool.java:0)
at com.mopo.audiofingerprinter.tageditor.ACRCloudRecognizer.recognizeByFile(ACRCloudRecognizer.java:129)
at com.mopo.audiofingerprinter.tageditor.TestActivity$RecThread.run(TestActivity.java:84)
The weird thing, is that the compiled project I cloned is working without errors. I have even attempted copying the classes from the demo and still it didn't work.
EDIT
After implementing Divy Soni's answer, the jniLibs folder disappeared entirely. And when I built the app it crashed with:
`09-18 11:21:46.848 26158-26798/com.mopo.audiofingerprinter E/UncaughtException: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.mopo.audiofingerprinter-1/base.apk", zip file "/data/app/com.mopo.audiofingerprinter-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.mopo.audiofingerprinter-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.mopo.audiofingerprinter-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.mopo.audiofingerprinter-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.mopo.audiofingerprinter-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.mopo.audiofingerprinter-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.mopo.audiofingerprinter-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.mopo.audiofingerprinter-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.mopo.audiofingerprinter-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.mopo.audiofingerprinter-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.mopo.audiofingerprinter-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.mopo.audiofingerprinter-1/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libACRCloudExtrTool.so"
at java.lang.Runtime.loadLibrary(Runtime.java:367)
at java.lang.System.loadLibrary(System.java:988)
at com.mopo.audiofingerprinter.tageditor.ACRCloudExtrTool.<clinit>(ACRCloudExtrTool.java:56)
at com.mopo.audiofingerprinter.tageditor.ACRCloudExtrTool.createFingerprintByFile(ACRCloudExtrTool.java:0)
at com.mopo.audiofingerprinter.tageditor.ACRCloudRecognizer.recognizeByFile(ACRCloudRecognizer.java:129)
at com.mopo.audiofingerprinter.tageditor.TestActivity$RecThread.run(TestActivity.java:84)`
EDIT2
Please note that the feaures I am using libACRCloudEngine.so is working perfectly. So it's libACRCloudExtrTool.so that is the problem here.
put this line in app build.gradle,it represent the path of .so files.
android {
.
.
sourceSets {
main {
jniLibs.srcDirs = ['jniLibs']
}
}
}

Android combine armeabi build only lib with new native code

I have an app using old so library compiled only for armeabi, But I have to write some new native code in C file NativeCode.c and compile it with app.
Old library is running correctly only when I set in the build.gradle
ndk {
moduleName "NativeCode"
abiFilters "armeabi"
}
But when I run app on arm64-v8a phone always get an error:
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.app.module, PID: 4199
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.app.module-2/base.apk"],nativeLibraryDirectories=[/data/app/com.app.module-2/lib/arm64, /data/app/com.app.module-2/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]] couldn't find "libnativecode.so"
at java.lang.Runtime.loadLibrary(Runtime.java:367)
at java.lang.System.loadLibrary(System.java:1076)
at com.app.module.util.NativeCode.<clinit>(NativeCode.java:25)
Is there any way to tell android studio to build native code only for armeabi ?

Realm causes my app to crash when trying to build a RealmConfiguration

I'm trying to use Realm as a database for high scores in my app. However, when this line of code is called:
realmConfig = new RealmConfiguration.Builder(getActivity().getApplicationContext()).build();
in the Fragment where I'm trying to save the user's score, I get this:
FATAL EXCEPTION: main
Process: com.tommy.mastersproject, PID: 21387
Theme: themes:{com.android.settings=overlay:com.cyngn.hexo, default=overlay:system, iconPack:system, fontPkg:system, com.android.systemui=overlay:system, com.android.systemui.navbar=overlay:system}
java.lang.NoClassDefFoundError: Failed resolution of: Lio/realm/RealmConfiguration$Builder;
at com.tommy.mastersproject.fragments.MemoryRecallFragment.onCreate(MemoryRecallFragment.java:144)
at android.support.v4.app.Fragment.performCreate(Fragment.java:1951)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1029)
at android.support.v4.app.BackStackRecord.setLastIn(BackStackRecord.java:779)
at android.support.v4.app.BackStackRecord.calculateFragments(BackStackRecord.java:802)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:660)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:601)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1238)
at android.app.Activity.performStart(Activity.java:6268)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "io.realm.RealmConfiguration$Builder" on path: DexPathList[[dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-support-annotations-23.4.0_d80f4a0fc2ae8e1f7cf76e4c536a48795da28487-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-library-2.4.0_e0d22a6e7ea9a4d2326a0c8c16bbc09d4d04442c-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-internal_impl-23.4.0_bd67bdb6ef0c094e8f4157e2567e8b30b9d0dd7f-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-com.jakewharton-butterknife-8.0.1_9246a0d023a2de89ba20a84f0fb1ecc6b733b004-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-com.code-troopers.betterpickers-library-3.0.0_f98f8b23c6650d93d8479a647f8f2162db8834e8-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-com.astuetz-pagerslidingtabstrip-1.0.1_474986b4f5d06e547dc72e3bf0988a95fa9d3973-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-com.android.support-support-vector-dr
I've also tried using
realm = Realm.getDefaultInstance();
but without any luck.
From a quick Google search, there have been similar complaints which were due to Realm's poor compatibility with the Android multidex and for not being up-to-date with Gradle, but I'm currently running Gradle 2.1.2.
I am also using Gradle 2.1.2 and Realm is working perfectly fine, problem could be with Instant Run, Did you try loading the project without Instant Run? If not disable it(In Android studio -> Preferences -> Build, Execution, Deployment -> Instant Run), clean the project and run it again.
If it does not work, share the actual code where you are creating RealmConfiguration and using Realm.

Categories

Resources