Android Jetpack Compose 在导入导航组合时崩溃
Android Jetpack Compose crashes when importing navigation compose
我正在尝试构建一个 Android JetPack Compose 应用程序。我的问题是,当我在 build.gradle:
中导入底部导航依赖项时
def nav_compose_version = "1.0.0-alpha01"
implementation "androidx.navigation:navigation-compose:$nav_compose_version"
当我 运行 应用程序时,它崩溃并出现以下错误:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.steganograph, PID: 10389
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/compose/foundation/Background;
at androidx.compose.foundation.BackgroundKt.background-1xq40Q0(Background.kt:44)
at androidx.compose.material.SurfaceKt.Surface-biUpMIw(Surface.kt:101)
at com.example.steganograph.MainActivity$onCreate.invoke(MainActivity.kt:19)
at com.example.steganograph.MainActivity$onCreate.invoke(Unknown Source:10)
at androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:144)
at androidx.compose.runtime.internal.ComposableLambda.invoke(Unknown Source:10)
at androidx.compose.runtime.AmbientKt.Providers(Ambient.kt:175)
at androidx.compose.foundation.TextKt.ProvideTextStyle(Text.kt:238)
Caused by: java.lang.ClassNotFoundException: androidx.compose.foundation.Background
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 64 more
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/compose/ui/platform/InspectableParameter;
... 64 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.compose.ui.platform.InspectableParameter" on path: DexPathList[[zip file "/data/app/com.example.steganograph-7xhzN_I613wLPbtTa4vTGQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.steganograph-7xhzN_I613wLPbtTa4vTGQ==/lib/arm64, /system/lib64, /system/vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 64 more
如果您使用的是 Compose 1.0.0-alpha07,则必须使用 Navigation Compose 1.0.0-alpha02,因为 Compose 的内部发生了很大变化,以至于生成了 alpha01(它是针对 Compose 1.0.0-alpha06 构建的) ) 不兼容。
我正在尝试构建一个 Android JetPack Compose 应用程序。我的问题是,当我在 build.gradle:
中导入底部导航依赖项时def nav_compose_version = "1.0.0-alpha01"
implementation "androidx.navigation:navigation-compose:$nav_compose_version"
当我 运行 应用程序时,它崩溃并出现以下错误:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.steganograph, PID: 10389
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/compose/foundation/Background;
at androidx.compose.foundation.BackgroundKt.background-1xq40Q0(Background.kt:44)
at androidx.compose.material.SurfaceKt.Surface-biUpMIw(Surface.kt:101)
at com.example.steganograph.MainActivity$onCreate.invoke(MainActivity.kt:19)
at com.example.steganograph.MainActivity$onCreate.invoke(Unknown Source:10)
at androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:144)
at androidx.compose.runtime.internal.ComposableLambda.invoke(Unknown Source:10)
at androidx.compose.runtime.AmbientKt.Providers(Ambient.kt:175)
at androidx.compose.foundation.TextKt.ProvideTextStyle(Text.kt:238)
Caused by: java.lang.ClassNotFoundException: androidx.compose.foundation.Background
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 64 more
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/compose/ui/platform/InspectableParameter;
... 64 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.compose.ui.platform.InspectableParameter" on path: DexPathList[[zip file "/data/app/com.example.steganograph-7xhzN_I613wLPbtTa4vTGQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.steganograph-7xhzN_I613wLPbtTa4vTGQ==/lib/arm64, /system/lib64, /system/vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 64 more
如果您使用的是 Compose 1.0.0-alpha07,则必须使用 Navigation Compose 1.0.0-alpha02,因为 Compose 的内部发生了很大变化,以至于生成了 alpha01(它是针对 Compose 1.0.0-alpha06 构建的) ) 不兼容。