【发布时间】:2021-05-14 17:07:17
【问题描述】:
我升级到 Jetpack Compose 1.0.0-alpha12 并开始遇到问题。
首先,我使用的 setContent 方法显示为已弃用。
从Alpha 12 release notes,我注意到它说:
ComponentActivity.setContent 已移至 androidx.activity:activity-compose 模块中的 androidx.activity.compose.setContent。 (Icf416)
所以我删除了我的 import androidx.compose.ui.platform.setContent 并将其切换到 import androidx.activity.compose.setContent,从而删除了弃用。
但是,然后我收到一条错误消息:
w: Flag is not supported by this version of the compiler: -Xallow-jvm-ir-dependencies
w: ATTENTION!
This build uses unsafe internal compiler arguments:
-XXLanguage:+NonParenthesizedAnnotationsOnFunctionalTypes
This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!
e: Classes compiled by an unstable version of the Kotlin compiler were found in dependencies.
Remove them from the classpath or use '-Xallow-unstable-dependencies' to suppress errors
e: /[my path]/MainActivity.kt: (39, 9): Class 'androidx.activity.compose.ComponentActivityKt' is
compiled by an unstable version of the Kotlin compiler and cannot be loaded by this compiler
再一次,我可以通过将我的 build.gradle 文件更改为:
kotlinOptions {
jvmTarget = '1.8'
useIR = true
// I added this line
freeCompilerArgs += "-Xallow-unstable-dependencies"
}
虽然这让我可以编译我的应用程序,但我现在在运行时遇到以下异常:
java.lang.NoSuchMethodError: No static method setContent(
Landroidx/activity/ComponentActivity;Landroidx/compose/runtime/Com
positionContext;Lkotlin/jvm/functions/Function2;)V in class
Landroidx/activity/compose/ComponentActivityKt; or its super classes
(declaration of 'androidx.activity.compose.ComponentActivityKt' appears in [my apk]
如何解决此问题并将我的应用升级到 Jetpack Compose 1.0.0-alpha12?
【问题讨论】:
标签: android android-activity android-jetpack-compose