gpt4 book ai didi

android - 喷气背包组合。预览不可用

转载 作者:行者123 更新时间:2023-12-05 04:34:33 24 4
gpt4 key购买 nike

有一个compose的项目。

项目中有2个模块:coreothergames(core依赖于othergames) .

我可以在 core 模块中成功看到撰写 View 的预览(用@Preview 注释)。但是当我尝试在 othergames 中查看预览时,无法显示预览并出现错误:

The following classes could not be instantiated:
- androidx.compose.ui.tooling.ComposeViewAdapter (Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE. If this is an unexpected error you can also try to build the project, then manually refresh the layout.

有详细信息:

java.lang.NoSuchFieldError: view_tree_saved_state_registry_owner
at androidx.savedstate.ViewTreeSavedStateRegistryOwner.set(ViewTreeSavedStateRegistryOwner.java:53)
at androidx.compose.ui.tooling.ComposeViewAdapter.init(ComposeViewAdapter.kt:666)
at androidx.compose.ui.tooling.ComposeViewAdapter.<init>(ComposeViewAdapter.kt:217)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:373)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:192)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:150)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:302)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:417)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:428)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:332)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
at android.view.LayoutInflater.inflate(LayoutInflater.java:663)
at android.view.LayoutInflater.inflate(LayoutInflater.java:505)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:361)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:436)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:121)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:727)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$7(RenderTask.java:883)
at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$2.run(RenderExecutor.kt:187)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)

这两个模块在 build.gradle 文件中有相同的 compose 依赖和设置:

    compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
useIR = true
}
buildFeatures {
compose true
}

composeOptions {
kotlinCompilerExtensionVersion '1.2.0-alpha03'
}

和:

dependencies {

...

implementation "androidx.compose.ui:ui:1.2.0-alpha03"
implementation "androidx.compose.ui:ui-tooling:1.2.0-alpha03"
implementation "androidx.compose.ui:ui-tooling-preview:1.2.0-alpha03"
implementation "androidx.compose.foundation:foundation:1.2.0-alpha03"
implementation "androidx.compose.foundation:foundation-layout:1.2.0-alpha03"
implementation "androidx.compose.material:material:1.2.0-alpha03"
implementation "androidx.compose.material:material-icons-core:1.2.0-alpha03"
implementation "androidx.compose.material:material-icons-extended:1.2.0-alpha03"
implementation "androidx.compose.animation:animation:1.2.0-alpha03"
implementation "androidx.compose.animation:animation-core:1.2.0-alpha03"
implementation "androidx.compose.animation:animation-graphics:1.2.0-alpha03"
implementation "androidx.compose.runtime:runtime-livedata:1.2.0-alpha03"
implementation "androidx.compose.compiler:compiler:1.2.0-alpha03"

...

为什么我在 othergames 模块中看不到预览?如何解决?

最佳答案

我找到了修复它的解决方案。在预览中断的模块中,我添加了最近删除的库:

implementation 'androidx.appcompat:appcompat:1.4.1'

一旦我这样做了,预览又出现了。我不确定这个库是不是真正的原因,因为 core 模块不包含这个库,但仍然显示预览。

更新:

时间过去了,我又遇到了这个问题。现在加上我上面说的库也不是解决不了的。我仍然不知道该怎么办。

关于android - 喷气背包组合。预览不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71203083/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com