kiwix / java-libkiwix

Libkiwix binding for Java & Kotlin
https://central.sonatype.com/artifact/org.kiwix/libkiwix
GNU General Public License v3.0
3 stars 4 forks source link

[REGRESSION] `JNIICU.setDataDirectory()` implementation not found #47

Closed MohitMaliFtechiz closed 1 year ago

MohitMaliFtechiz commented 1 year ago

While refactoring the kiwix-android to compile with java-libkiwix wrapper we faced the no implementation found error for JNIICU.setDataDirectory() method of the wrapper.

Logs:

FATAL EXCEPTION: main
Process: org.kiwix.kiwixmobile, PID: 27046
java.lang.UnsatisfiedLinkError: No implementation found for void org.kiwix.libkiwix.JNIICU.setDataDirectory(java.lang.String) (tried Java_org_kiwix_libkiwix_JNIICU_setDataDirectory and Java_org_kiwix_libkiwix_JNIICU_setDataDirectory__Ljava_lang_String_2)
at org.kiwix.libkiwix.JNIICU.setDataDirectory(Native Method)
at org.kiwix.libkiwix.JNIKiwix.setDataDirectory(JNIKiwix.java:35)
at org.kiwix.kiwixmobile.core.JNIInitialiser.<init>(JNIInitialiser.kt:36)
at org.kiwix.kiwixmobile.core.di.components.DaggerCoreComponent$CoreComponentImpl.jNIInitialiser(DaggerCoreComponent.java:528)
at org.kiwix.kiwixmobile.core.di.components.DaggerCoreComponent$CoreComponentImpl.injectCoreApp(DaggerCoreComponent.java:734)
at org.kiwix.kiwixmobile.core.di.components.DaggerCoreComponent$CoreComponentImpl.inject(DaggerCoreComponent.java:699)
at org.kiwix.kiwixmobile.core.CoreApp.onCreate(CoreApp.kt:81)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1211)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7094)
at android.app.ActivityThread.access$1700(ActivityThread.java:275)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2168)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:210)
at android.os.Looper.loop(Looper.java:299)
at android.app.ActivityThread.main(ActivityThread.java:8280)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:576)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1073)

Since this method is not set on the Android side we have commented this code to test the other parts of the wrapper in Android. It is crashing on the server and search functionality.

For server the logs:

Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 29404 (wix.kiwixmobile), pid 29404 (wix.kiwixmobile)
Cmdline: org.kiwix.kiwixmobile
pid: 29404, tid: 29404, name: wix.kiwixmobile  >>> org.kiwix.kiwixmobile <<<
#00 pc 0000000000292b00  /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!libkiwix.so (kiwix::removeAccents(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&)+200)
#01 pc 000000000021ce84  /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!libkiwix.so
#02 pc 000000000021a550  /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!libkiwix.so (kiwix::Library::updateBookDB(kiwix::Book const&)+364)
#03 pc 000000000021a0e4  /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!libkiwix.so (kiwix::Library::addBook(kiwix::Book const&)+80)
#04 pc 0000000000013b7c  /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!libkiwix_wrapper.so (Java_org_kiwix_libkiwix_Library_addBook+248) (BuildId: 2be3a7525f3187f9c4d6b9966b70d4d6748ca847)
#07 pc 0000000000002ae8  [anon:dalvik-classes19.dex extracted in memory from /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!classes19.dex] (org.kiwix.kiwixmobile.webserver.KiwixServer$Factory.createKiwixServer+148)
#09 pc 000000000000330c  [anon:dalvik-classes19.dex extracted in memory from /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!classes19.dex] (org.kiwix.kiwixmobile.webserver.WebServerHelper.startAndroidWebServer+48)
#11 pc 000000000000340a  [anon:dalvik-classes19.dex extracted in memory from /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!classes19.dex] (org.kiwix.kiwixmobile.webserver.WebServerHelper.startServerHelper+110)
#13 pc 000000000000626a  [anon:dalvik-classes17.dex extracted in memory from /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!classes17.dex] (org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotService.onStartCommand+142)

And for search, while we are using getEstimatedMatches() function of the Search class it crashes.

Logs:

Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 28887 (DefaultDispatch), pid 28740 (wix.kiwixmobile)
Cmdline: org.kiwix.kiwixmobile
pid: 28740, tid: 28887, name: DefaultDispatch  >>> org.kiwix.kiwixmobile <<<
#00 pc 0000000000218b04  /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!libzim.so (zim::removeAccents(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&)+308)
#01 pc 0000000000254c80  /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!libzim.so (zim::SuggestionSearch::getEnquire() const+144)
#02 pc 0000000000254a48  /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!libzim.so (zim::SuggestionSearch::getEstimatedMatches() const+48)
#03 pc 0000000000026808  /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!libzim_wrapper.so (Java_org_kiwix_libzim_SuggestionSearch_getEstimatedMatches+124) (BuildId: acdad51494996579e69008b10b915288d32f13e9)
#06 pc 0000000000009dc6  /data/data/org.kiwix.kiwixmobile/code_cache/.overlay/base.apk/classes11.dex (org.kiwix.kiwixmobile.core.search.viewmodel.ZimSearchResultGenerator.readResultsFromZim+386)
#08 pc 0000000000009a06  /data/data/org.kiwix.kiwixmobile/code_cache/.overlay/base.apk/classes11.dex (org.kiwix.kiwixmobile.core.search.viewmodel.ZimSearchResultGenerator.access$readResultsFromZim+18)
#10 pc 00000000000094a6  /data/data/org.kiwix.kiwixmobile/code_cache/.overlay/base.apk/classes11.dex (org.kiwix.kiwixmobile.core.search.viewmodel.ZimSearchResultGenerator$readResultsFromZim$1.invokeSuspend+38)
#12 pc 000000000016c766  [anon:dalvik-classes30.dex extracted in memory from /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!classes30.dex] (kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith+78)
#14 pc 00000000001d7c7c  [anon:dalvik-classes30.dex extracted in memory from /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!classes30.dex] (kotlinx.coroutines.DispatchedTask.run+512)
#16 pc 0000000000232c04  [anon:dalvik-classes30.dex extracted in memory from /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!classes30.dex] (kotlinx.coroutines.internal.LimitedDispatcher.run+64)
#18 pc 000000000023ff3e  [anon:dalvik-classes30.dex extracted in memory from /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!classes30.dex] (kotlinx.coroutines.scheduling.TaskImpl.run+18)
#20 pc 000000000023e5be  [anon:dalvik-classes30.dex extracted in memory from /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!classes30.dex] (kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely+18)
#22 pc 000000000023c706  [anon:dalvik-classes30.dex extracted in memory from /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!classes30.dex] (kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask+74)
#24 pc 000000000023c938  [anon:dalvik-classes30.dex extracted in memory from /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!classes30.dex] (kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker+128)
#26 pc 000000000023c894  [anon:dalvik-classes30.dex extracted in memory from /data/app/~~ScoK14NZTlGh-DIVTr-gHA==/org.kiwix.kiwixmobile-wbt86NIt8qEBn1s-gqFwHg==/base.apk!classes30.dex] (kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run+8)

I suspect that it is crashing on these functionalities because we have not set JNIICU.setDataDirectory on the Android side.

kelson42 commented 1 year ago

@MohitMaliFtechiz This is a regression, please fix! Please also publish a list of all libzim and libkiwix API which are not available here.

MohitMaliFtechiz commented 1 year ago

@mgautierfr, Why did the wrapper failing to find the implementation of JNIICU.setDataDirectory, since we are compiling the wrapper correctly(we have this method in tools.h, kiwixicu.cpp) so it should find the implementation of this method. Are we missing something on libzim or java-libkiwix side?

mgautierfr commented 1 year ago

@MohitMaliFtechiz I have found the problem. Can you test #48 on your side ?

MohitMaliFtechiz commented 1 year ago

hi @mgautierfr, Thanks for your quick fix, now it is finding the implantation of this JNIICU.setDataDirectory as well as now it is not crashing while starting the server and search functionality which was reported in this issue.