我正在Kotlin Multiplatform的帮助下开发一个虚拟天气应用程序。我正在使用Decompose和MVIKotlin来尝试和共享除本地ui、用于IOS的SwiftUI和用于桌面和Android的Compose之外的所有业务逻辑。
我正在尝试有一个预期的可合成(用于暗主题和加载图像)
// In common main
@Composable
expect fun isDarkMode() : Boolean
@Composable
expect fun loadWeatherIcon(id : Int) : Painter
// In android main
@Composable
actual fun isDarkMode() : Boolean {
return androidx.compose.foundation.isSystemInDarkTheme()
}
@Composable
actual fun loadWeatherIcon(id : Int) : Painter {
return painterResource(id)
}
//In Desktop main
@Composable
actual fun isDarkMode() : Boolean {
return false //isSystemInDarkTheme()
}
@Composable
actual fun loadWeatherIcon(id : Int) : Painter {
return loadWeatherIcon(id)
}
这意味着它们都已实现并存在,但由于某种原因,崩溃发生在NoSuchMethodError上。我发现了一些类似的问题,但它们都有暂停乐趣和默认参数。同时,我的方法应该像在喷气背包待办事项撰写示例中一样工作,这是我的项目(如果您想测试正在发生的事情,您可以克隆它并运行它,它应该立即崩溃)
https://github . com/尼古拉-米洛维奇/科特林多平台-天气应用程序
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.nikolam.kmm_weather.androidApp, PID: 17270
java.lang.NoSuchMethodError: No static method isDarkMode(Landroidx/compose/runtime/Composer;I)Z in class Lcom/nikolam/kmm_weather/ui/UtilsKt; or its super classes (declaration of 'com.nikolam.kmm_weather.ui.UtilsKt' appears in /data/data/com.nikolam.kmm_weather.androidApp/code_cache/.overlay/base.apk/classes4.dex)
at com.nikolam.kmm_weather.ui.WeatherMainContentKt$WeatherMainContent$2.invoke(WeatherMainContent.kt:45)
at com.nikolam.kmm_weather.ui.WeatherMainContentKt$WeatherMainContent$2.invoke(WeatherMainContent.kt:38)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:193)
at com.nikolam.kmm_weather.ui.WeatherMainContentKt.WeatherMainContent(WeatherMainContent.kt:38)
at com.nikolam.kmm_weather.ui.ComposableSingletons$WeatherRootContentKt$lambda-1$1.invoke(WeatherRootContent.kt:14)
at com.nikolam.kmm_weather.ui.ComposableSingletons$WeatherRootContentKt$lambda-1$1.invoke(WeatherRootContent.kt:12)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:118)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at com.arkivanov.decompose.extensions.compose.jetbrains.ChildrenKt$Children$1$1.invoke(Children.kt:30)
at com.arkivanov.decompose.extensions.compose.jetbrains.ChildrenKt$Children$1$1.invoke(Children.kt:29)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:193)
at androidx.compose.runtime.saveable.SaveableStateHolderImpl.SaveableStateProvider(SaveableStateHolder.kt:84)
at com.arkivanov.decompose.extensions.compose.jetbrains.ChildrenKt$Children$1.invoke(Children.kt:29)
at com.arkivanov.decompose.extensions.compose.jetbrains.ChildrenKt$Children$1.invoke(Children.kt:28)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:118)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at com.arkivanov.decompose.extensions.compose.jetbrains.animation.page.PageAnimationKt$PageAnimationFrame$1$1$1.invoke(PageAnimation.kt:143)
at com.arkivanov.decompose.extensions.compose.jetbrains.animation.page.PageAnimationKt$PageAnimationFrame$1$1$1.invoke(PageAnimation.kt:141)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:118)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at com.arkivanov.decompose.extensions.compose.jetbrains.animation.child.CrossfadeScaleKt$crossfadeScale$1.invoke(CrossfadeScale.kt:22)
at com.arkivanov.decompose.extensions.compose.jetbrains.animation.child.CrossfadeScaleKt$crossfadeScale$1.invoke(CrossfadeScale.kt:21)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:254)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at com.arkivanov.decompose.extensions.compose.jetbrains.animation.page.PageAnimationKt$PageAnimationFrame$1.invoke(PageAnimation.kt:141)
at com.arkivanov.decompose.extensions.compose.jetbrains.animation.page.PageAnimationKt$PageAnimationFrame$1.invoke(PageAnimation.kt:132)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:118)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.foundation.layout.BoxWithConstraintsKt$BoxWithConstraints$1$1$measurables$1.invoke(BoxWithConstraints.kt:61)
E/AndroidRuntime: at androidx.compose.foundation.layout.BoxWithConstraintsKt$BoxWithConstraints$1$1$measurables$1.invoke(BoxWithConstraints.kt:61)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.ui.layout.SubcomposeLayoutState$subcompose$2$1.invoke(SubcomposeLayout.kt:167)
at androidx.compose.ui.layout.SubcomposeLayoutState$subcompose$2$1.invoke(SubcomposeLayout.kt:167)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.ComposerKt.invokeComposable(Composer.kt:3235)
at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:2514)
at androidx.compose.runtime.ComposerImpl.composeContent$runtime_debug(Composer.kt:2478)
at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:453)
at androidx.compose.runtime.Recomposer.composeInitial$runtime_debug(Recomposer.kt:702)
at androidx.compose.runtime.ComposerImpl$CompositionContextImpl.composeInitial$runtime_debug(Composer.kt:2914)
at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:409)
at androidx.compose.ui.layout.SubcomposeLayoutState.subcomposeInto(SubcomposeLayout.kt:184)
at androidx.compose.ui.layout.SubcomposeLayoutState.access$subcomposeInto(SubcomposeLayout.kt:100)
at androidx.compose.ui.layout.SubcomposeLayoutState$subcompose$2.invoke(SubcomposeLayout.kt:160)
at androidx.compose.ui.layout.SubcomposeLayoutState$subcompose$2.invoke(SubcomposeLayout.kt:158)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.withNoObservations(SnapshotStateObserver.kt:137)
at androidx.compose.ui.node.OwnerSnapshotObserver.withNoSnapshotReadObservation$ui_debug(OwnerSnapshotObserver.kt:49)
at androidx.compose.ui.node.LayoutNode.withNoSnapshotReadObservation$ui_debug(LayoutNode.kt:1054)
at androidx.compose.ui.layout.SubcomposeLayoutState.subcompose(SubcomposeLayout.kt:158)
at androidx.compose.ui.layout.SubcomposeLayoutState.subcompose(SubcomposeLayout.kt:152)
at androidx.compose.foundation.layout.BoxWithConstraintsKt$BoxWithConstraints$1$1.invoke-0kLqBqw(BoxWithConstraints.kt:61)
at androidx.compose.foundation.layout.BoxWithConstraintsKt$BoxWithConstraints$1$1.invoke(BoxWithConstraints.kt:59)
at androidx.compose.ui.layout.SubcomposeLayoutState$createMeasurePolicy$1.measure-3p2s80s(SubcomposeLayout.kt:212)
at androidx.compose.ui.node.InnerPlaceable.measure-BRTryo0(InnerPlaceable.kt:45)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:95)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:94)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:121)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_debug(OwnerSnapshotObserver.kt:75)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_debug(OwnerSnapshotObserver.kt:63)
at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:94)
at androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(OuterMeasurablePlaceable.kt:68)
at androidx.compose.ui.node.LayoutNode.measure-BRTryo0(LayoutNode.kt:1172)
at androidx.compose.foundation.layout.BoxKt$boxMeasurePolicy$1.measure-3p2s80s(Box.kt:111)
at androidx.compose.ui.node.InnerPlaceable.measure-BRTryo0(InnerPlaceable.kt:45)
at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.measure-3p2s80s(GraphicsLayerModifier.kt:213)
at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:37)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:108)
E/AndroidRuntime: at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.measure-3p2s80s(GraphicsLayerModifier.kt:213)
at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:37)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:95)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:94)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:121)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_debug(OwnerSnapshotObserver.kt:75)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_debug(OwnerSnapshotObserver.kt:63)
at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:94)
at androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(OuterMeasurablePlaceable.kt:68)
at androidx.compose.ui.node.LayoutNode.measure-BRTryo0(LayoutNode.kt:1172)
at androidx.compose.ui.layout.RootMeasurePolicy.measure-3p2s80s(RootMeasurePolicy.kt:38)
at androidx.compose.ui.node.InnerPlaceable.measure-BRTryo0(InnerPlaceable.kt:45)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:108)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:108)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:108)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:108)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:95)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:94)
at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:1787)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:116)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_debug(OwnerSnapshotObserver.kt:75)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_debug(OwnerSnapshotObserver.kt:63)
at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:94)
at androidx.compose.ui.node.LayoutNode.remeasure-BRTryo0$ui_debug(LayoutNode.kt:1179)
at androidx.compose.ui.node.MeasureAndLayoutDelegate.doRemeasure-0kLqBqw(MeasureAndLayoutDelegate.kt:170)
at androidx.compose.ui.node.MeasureAndLayoutDelegate.html" target="_blank">access$doRemeasure-0kLqBqw(MeasureAndLayoutDelegate.kt:39)
at androidx.compose.ui.node.MeasureAndLayoutDelegate.measureAndLayout(MeasureAndLayoutDelegate.kt:212)
at androidx.compose.ui.platform.AndroidComposeView.onMeasure(AndroidComposeView.android.kt:543)
at android.view.View.measure(View.java:25466)
at androidx.compose.ui.platform.AbstractComposeView.onMeasure(ComposeView.android.kt:249)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:145)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
E/AndroidRuntime: at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:747)
at android.view.View.measure(View.java:25466)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3397)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:2228)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2486)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1952)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8171)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:972)
at android.view.Choreographer.doCallbacks(Choreographer.java:796)
at android.view.Choreographer.doFrame(Choreographer.java:731)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
I/Process: Sending signal. PID: 17270 SIG:
我遇到了一个类似的问题,在不同的Gradle模块中,@Composable
注释的预期函数在运行时不可见。因此,java.lang.NoSuch方法错误
异常。解决方案是使预期函数内部化,并将公共包装函数委托给该内部函数。
崩溃:
@Composable
expect fun Image() { ... }
不崩溃:
@Composable
internal expect fun InternalImage() { ... }
@Composable
fun Image() {
InternalImage()
}
问题内容: 我面临一个非常奇怪的问题。我有一套每天在Jenkins上运行的测试,并且没有任何明显的变化,一些断言(期望)开始失败。奇怪的是,只有当我在Browserstack上从Jenkins执行测试时,它们才会失败。在本地一切正常,在浏览器堆栈本地一切正常,在saucelabs上一切正常。我有3个具有类似期望的it()块: 它们都位于不同的it()块中。现在奇怪的是: 当我执行测试时,使用第一个
键 描述 值 automationName 自动化测试的引擎 Appium (默认)或者 Selendroid platformName 使用的手机操作系统 iOS, Android, 或者 FirefoxOS platformVersion 手机操作系统的版本 例如 7.1, 4.4 deviceName 使用的手机或模拟器类型 iPhone Simulator, iPad Simulator,
问题内容: 我正在从python脚本中调用一个so文件。据我了解,我真的不需要释放使用ctypes在python中打开的共享库。但是,在我的so文件代码中,它dlopen另一个so文件并且不执行dlclose()。在这种情况下,从python端使用安全吗?我不必释放在ctypes内部加载的共享库soe文件吗? 问题答案: 始终遵循 “自己清洁后清理 ”的规则(尽管现代技术会为您提供清洁方面的帮助)
Kotlin-Multiplatform (Android, iOS, JS & JVM Desktop App) This example shows how to create a simple Android/iOS/JVM/JS project sharing some Kotlin code. This app saves on a local database your favouri
在调用的返回类型中,的预期类型无法与实际类型匹配。可能的原因:应用于表达式:公式中中的参数太少: 在的第二个参数中,即表达式:中的中的与实际类型在方程中的无法匹配: 为什么不管用?我不能理解。请帮我一把。这些错误是可以理解的,但我不知道它们的原因。
问题内容: 是否可以使用Go创建共享库(.so)? 更新 :为此创建了一个“ 问题 ”。 问题答案: 现在可以使用标志 您需要做的是首先运行以下命令: (以上代码使所有通用软件包都可共享!)然后 最后,在编译代码时,您需要运行: 上面这些就是什么,而不是静态链接所有内容而仅动态链接它们,您最终将获得更小的编译文件。为了让您了解我的带有静态链接的“ hello.go”文件为2.3MB,而使用动态链接