MobileNativeFoundation / Store

A Kotlin Multiplatform library for building network-resilient applications
https://mobilenativefoundation.github.io/Store/
Apache License 2.0
3.18k stars 203 forks source link

Store Not Fetching or Read/Writing #584

Closed mastrgamr closed 11 months ago

mastrgamr commented 11 months ago

Library Version: org.mobilenativefoundation.store:store5:5.0.0

Hello, I'm reaching out for guidance on how to bootstrap a project. I tried to get insight into how to implement this by referencing the howl repo, which seems to be a bit outdated from the latest Store library version?

I recently came across this project and thought it'd be cool to get a prototype up and running with a sample project that displays data from a random public API. I'm having an issue fetching, and saving data to the Store. I'm finding it hard to debug because I don't know what the issue is and the logs I try to generate don't show any helpful info.

Logcat output (beginning from app startup)

``` 17:14:07.611 E Loaded layer handle (7617246676022877449) for layer /my_product/lib64/libcolorx-loader.so 17:14:07.611 E Looking for entrypoint ColorX_Check 17:14:07.611 E Found ColorX_Check for /my_product/lib64/libcolorx-loader.so 17:14:07.611 E Check failed 17:14:07.624 I Unknow feature:IOplusTextViewRTLUtilForUG 17:14:07.656 D init sDebug to false, init sDebugIme to false, init sAlwaysOn to false 17:14:07.656 D updateDebugToClass InputMethodManager.DEBUG = false 17:14:07.656 D updateDebugToClass ImeFocusController.DEBUG = false 17:14:07.656 D updateDebugToClass BaseInputConnection.DEBUG = false 17:14:07.656 D updateDebugToClass ImeFocusController.sDebugIme = false 17:14:07.659 D createInstance(64bit) : createExtendedFactory 17:14:07.659 D Opened libguiextimpl.so 17:14:07.664 D Add to mViews: DecorView@8f01699[MainActivity],pkg= com.example.kmptest.android 17:14:07.665 D createInstance(64bit) : createExtendedFactory 17:14:07.667 I checkListMode: is blacklist mode = true 17:14:07.667 D Opened libhwuiextimpl.so 17:14:07.668 D createInstance(64bit) : createExtendedFactory 17:14:07.668 D Opened libSchedAssistExtImpl.so 17:14:07.681 D Input log is disabled 17:14:07.692 E [OplusViewMirrorManager] updateHostViewRootIfNeeded, not support android.view.ViewRootImpl@35e6ef8 17:14:07.761 W Method java.lang.Object androidx.compose.runtime.snapshots.SnapshotStateMap.mutate(kotlin.jvm.functions.Function1) failed lock verification and will run slower. Common causes for lock verification issues are non-optimized dex code and incorrect proguard optimizations. 17:14:07.761 W Method void androidx.compose.runtime.snapshots.SnapshotStateMap.update(kotlin.jvm.functions.Function1) failed lock verification and will run slower. 17:14:07.761 W Method boolean androidx.compose.runtime.snapshots.SnapshotStateMap.removeIf$runtime_release(kotlin.jvm.functions.Function1) failed lock verification and will run slower. 17:14:07.812 W SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". 17:14:07.812 W SLF4J: Defaulting to no-operation (NOP) logger implementation 17:14:07.813 W SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. 17:14:07.895 D [](id:48e00000000,api:0,p:-1,c:1166) connect: controlledByApp=false 17:14:07.895 D createInstance(64bit) : createExtendedFactory 17:14:07.895 D Opened libSchedAssistExtImpl.so 17:14:07.898 I QUALCOMM build : 5a9022f91f, Ib11adbd47c Build Date : 07/26/21 OpenGL ES Shader Compiler Version: EV031.35.01.09 Local Branch : Remote Branch : Remote Branch : Reconstruct Branch : 17:14:07.898 I Build Config : S P 10.0.7 AArch64 17:14:07.898 I Driver Path : /vendor/lib64/egl/libGLESv2_adreno.so 17:14:07.902 I PFP: 0x016dc094, ME: 0x00000000 17:14:07.906 D registerCallbacksForSync syncBuffer=false 17:14:07.910 D GrGLMakeAssembledInterface verStr OpenGL ES 3.2 V@0530.0 (GIT@5a9022f91f, Ib11adbd47c, 1627309424) (Date:07/26/21) 17:14:07.910 D GrGLMakeAssembledGLESInterface verStr OpenGL ES 3.2 V@0530.0 (GIT@5a9022f91f, Ib11adbd47c, 1627309424) (Date:07/26/21) 17:14:07.911 D extensions init verString=OpenGL ES 3.2 V@0530.0 (GIT@5a9022f91f, Ib11adbd47c, 1627309424) (Date:07/26/21) 17:14:07.914 D [VRI[MainActivity]#0(BLAST Consumer)0](id:48e00000000,api:1,p:1166,c:1166) connect: api=1 producerControlledByApp=true 17:14:07.928 D Received frameCommittedCallback lastAttemptedDrawFrameNum=1 didProduceBuffer=true syncBuffer=false 17:14:07.929 W Expecting binder but got null! 17:14:07.930 D draw finished. 17:14:07.941 I getting x :: 17:14:07.941 I COINCAP STORE ==== org.mobilenativefoundation.store.store5.impl.RealMutableStore@ad530f9 17:14:07.944 I BEFORE READ ==== ByCoinSymbol(coinSymbol=btc) 17:14:07.952 I Skipped: false 13 cost 220.13783 refreshRate 16555874 bit true processName com.example.kmptest.android 17:14:07.956 D onFocusEvent true 17:14:07.956 D send msg MSG_WINDOW_FOCUS_CHANGED with caller android.view.ViewRootImplExtImpl.markAndDumpWindowFocusChangeMsg:956 android.view.ViewRootImpl.windowFocusChanged:9837 android.view.ViewRootImpl$WindowInputEventReceiver.onFocusEvent:9550 android.os.MessageQueue.nativePollOnce:-2 android.os.MessageQueue.next:349 android.os.Looper.loopOnce:186 android.os.Looper.loop:351 android.app.ActivityThread.main:8422 java.lang.reflect.Method.invoke:-2 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run:584 com.android.internal.os.ZygoteInit.main:1013 17:14:07.960 D handleWindowFocusChanged mWindowFocusChanged true mUpcomingWindowFocus true mAdded true 17:14:08.962 D com.example.kmptest.android/com.example.kmptest.android.MainActivity,This DecorView@8f01699[MainActivity] change focus to true ```

disclaimer: I have no experience with Koin (let alone KMP)

To Reproduce

Build/Run the prototype app

Expected behavior The Composable should display a response from the Store query

matt-ramotar commented 11 months ago

On a quick look, it looks like your SOT is only emitting if there is data. Try adding an else condition here and emitting null

matt-ramotar commented 11 months ago

I'm not seeing any networking logs, so I'd also step through here to make sure you are getting a response and deserializing it correctly

mastrgamr commented 11 months ago

Thanks for the insight matt. I am deserializing from the network correctly but for some reason I get a ReadExcpetion and vague WriteException (with no cause output to logs?). The only clues I might have is SQLDelight's executeAsOne() function not returning a value. My console is not showing an output when running the function. I'm thinking because there's nothing being returned from the SourceOfTruth reader function it's causing Store to fail Read/Write

Here's my latest logs:

``` 15:42:31.020 D Installing profile for com.example.kmptest.android 15:42:33.337 D Add to mViews: DecorView@ba3669d[MainActivity],pkg= com.example.kmptest.android 15:42:33.338 D createInstance(64bit) : createExtendedFactory 15:42:33.339 D Opened libhwuiextimpl.so 15:42:33.339 D createInstance(64bit) : createExtendedFactory 15:42:33.339 D Opened libSchedAssistExtImpl.so 15:42:33.353 D Input log is disabled 15:42:33.357 I Skipped: false 1 cost 29.67948 refreshRate 16556183 bit true processName com.example.kmptest.android 15:42:33.358 E [OplusViewMirrorManager] updateHostViewRootIfNeeded, not support android.view.ViewRootImpl@a44b0c 15:42:33.430 W Method java.lang.Object androidx.compose.runtime.snapshots.SnapshotStateMap.mutate(kotlin.jvm.functions.Function1) failed lock verification and will run slower. Common causes for lock verification issues are non-optimized dex code and incorrect proguard optimizations. 15:42:33.430 W Method void androidx.compose.runtime.snapshots.SnapshotStateMap.update(kotlin.jvm.functions.Function1) failed lock verification and will run slower. 15:42:33.430 W Method boolean androidx.compose.runtime.snapshots.SnapshotStateMap.removeIf$runtime_release(kotlin.jvm.functions.Function1) failed lock verification and will run slower. 15:42:33.540 D [](id:213e00000000,api:0,p:-1,c:8510) connect: controlledByApp=false 15:42:33.540 D createInstance(64bit) : createExtendedFactory 15:42:33.541 D Opened libSchedAssistExtImpl.so 15:42:33.542 I QUALCOMM build : 5a9022f91f, Ib11adbd47c Build Date : 07/26/21 OpenGL ES Shader Compiler Version: EV031.35.01.09 Local Branch : Remote Branch : Remote Branch : Reconstruct Branch : 15:42:33.542 I Build Config : S P 10.0.7 AArch64 15:42:33.542 I Driver Path : /vendor/lib64/egl/libGLESv2_adreno.so 15:42:33.546 I PFP: 0x016dc094, ME: 0x00000000 15:42:33.548 D registerCallbacksForSync syncBuffer=false 15:42:33.554 D GrGLMakeAssembledInterface verStr OpenGL ES 3.2 V@0530.0 (GIT@5a9022f91f, Ib11adbd47c, 1627309424) (Date:07/26/21) 15:42:33.554 D GrGLMakeAssembledGLESInterface verStr OpenGL ES 3.2 V@0530.0 (GIT@5a9022f91f, Ib11adbd47c, 1627309424) (Date:07/26/21) 15:42:33.554 D extensions init verString=OpenGL ES 3.2 V@0530.0 (GIT@5a9022f91f, Ib11adbd47c, 1627309424) (Date:07/26/21) 15:42:33.557 D [VRI[MainActivity]#0(BLAST Consumer)0](id:213e00000000,api:1,p:8510,c:8510) connect: api=1 producerControlledByApp=true 15:42:33.567 D Received frameCommittedCallback lastAttemptedDrawFrameNum=1 didProduceBuffer=true syncBuffer=false 15:42:33.569 W Expecting binder but got null! 15:42:33.569 D draw finished. 15:42:33.571 I initFrameRateConfig: levels: [120, 60, 40, 30] thresholds: [400, 80, 30] scrollbar fade frame rate: 0 15:42:33.571 I FRTCConfigManager: FRTC_CAPABILITY = 120, package name = com.example.kmptest.android, PACKAGE_ENABLE = false 15:42:33.571 I init info: mPackageName = com.example.kmptest.android, mIsEnabled = false 15:42:33.599 W SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". 15:42:33.599 W SLF4J: Defaulting to no-operation (NOP) logger implementation 15:42:33.599 W SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. 15:42:33.620 I CoinCapStoreRepository: COINCAP STORE ==== org.mobilenativefoundation.store.store5.impl.RealMutableStore@f541afd 15:42:33.623 I BEFORE READ ==== ByCoinSymbol(coinSymbol=btc) 15:42:33.633 I Debug: (Store) org.mobilenativefoundation.store.store5.internal.result.EagerConflictResolutionResult$Success$NoConflicts@c4c69f9 15:42:33.638 I CoinCapStoreRepository: STORE RESPONSE ==== Loading(origin=Fetcher(name=null)) 15:42:33.640 D onFocusEvent true 15:42:33.640 D send msg MSG_WINDOW_FOCUS_CHANGED with caller android.view.ViewRootImplExtImpl.markAndDumpWindowFocusChangeMsg:956 android.view.ViewRootImpl.windowFocusChanged:9837 android.view.ViewRootImpl$WindowInputEventReceiver.onFocusEvent:9550 android.os.MessageQueue.nativePollOnce:-2 android.os.MessageQueue.next:349 android.os.Looper.loopOnce:186 android.os.Looper.loop:351 android.app.ActivityThread.main:8422 java.lang.reflect.Method.invoke:-2 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run:584 com.android.internal.os.ZygoteInit.main:1013 15:42:33.640 I Skipped: false 14 cost 242.03223 refreshRate 16556112 bit true processName com.example.kmptest.android 15:42:33.648 D handleWindowFocusChanged mWindowFocusChanged true mUpcomingWindowFocus true mAdded true 15:42:33.650 I BEFORE FETCH ==== ByCoinSymbol(coinSymbol=btc) 15:42:33.681 D tagSocket(129) with statsTag=0xffffffff, statsUid=-1 15:42:34.183 I FETCH SUCCESS ==== CoinData(id=bitcoin, symbol=BTC, name=Bitcoin, priceUsd=37461.9503645104936973, changePercent24Hr=1.0120296868655979) 15:42:34.185 I CONVERTING NETWORK TO OUTPUT ===== Success(data=CoinData(id=bitcoin, symbol=BTC, name=Bitcoin, priceUsd=37461.9503645104936973, changePercent24Hr=1.0120296868655979)) 15:42:34.185 I CONVERTED NETWORK TO OUTPUT CoinData(id=bitcoin, symbol=BTC, name=Bitcoin, priceUsd=37461.9503645104936973, changePercent24Hr=1.0120296868655979) 15:42:34.187 I BEFORE READ ==== ByCoinSymbol(coinSymbol=btc) 15:42:34.189 I CoinCapStoreRepository: STORE RESPONSE ==== Exception(error=org.mobilenativefoundation.store.store5.SourceOfTruth$WriteException: Failed to write value to Source of Truth. key: ByCoinSymbol(coinSymbol=btc), origin=org.mobilenativefoundation.store.store5.StoreReadResponseOrigin$SourceOfTruth@79cac14) 15:42:34.189 I CoinCapStoreRepository: STORE RESPONSE ==== Exception(error=org.mobilenativefoundation.store.store5.SourceOfTruth$ReadException: Failed to read from Source of Truth. key: ByCoinSymbol(coinSymbol=btc), origin=org.mobilenativefoundation.store.store5.StoreReadResponseOrigin$SourceOfTruth@79cac14) 15:42:34.648 D com.example.kmptest.android/com.example.kmptest.android.MainActivity,This DecorView@ba3669d[MainActivity] change focus to true ```
matt-ramotar commented 11 months ago

It looks like you aren't hitting this: https://github.com/mastrgamr/KMP-Store-Prototype/blob/11fbfeedf77644a4238db9a4b6df6ca6e572eca3/shared/src/commonMain/kotlin/com/example/kmptest/store/coindata/sot/CoinCapSourceOfTruthProvider.kt#L36

We write to the SOT after fetching from network. Can you try removing the require statement and switching on the ByCoinSymbol key?

mastrgamr commented 11 months ago

Thanks a lot for the help. I managed to get my prototype up and running just fine. I was following the code and realized SourceOfTruth's reader/writer functions are executed using the same key given to query the Store. The require() method gave it away, guess I must restructure my CoinDataKey

Love the library!

matt-ramotar commented 11 months ago

Awesome! Happy to help if anything else comes up