问题描绘
报错信息
java.lang.NoSuchMethodError: No static method setContent$default(Landroidx/activity
/ComponentActivity;Landroidx/compose/runtime/CompositionContext;Lkotlin/jvm/functions
/Function0;ILjava/lang/Object;)V in class Landroidx/activity/compose/ComponentActivityKt;
or its super classes (declaration of 'androidx.activity.compose.ComponentActivityKt'
appears in /data/app/com.otter.player-Lx0SJMeWfCnOQZyMcc4S4w==/base.apk)at \
com.otter.player.MainActivity.onCreate(MainActivity.kt:18)
呈现的这个问题比较恶心,编译啥的都能通过,也能安装成功,但是就是运转无法成功,发动就闪退。
问题处理
在网上有人说在app下的build.gradle中的android{}
下增加如下的代码
buildFeatures {
compose = true
}
这样又会引起一个过错,版别兼容的过错:如下所示 报错的信息大致为:
This version (1.0.5) of the Compose Compiler requires Kotlin version 1.5.31 but you appear to
be using Kotlin version 1.7.10 which is not known to be compatible. Please fix your
configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn
you!).
要彻底处理这个问题,还需要在android{}
增加如下代码:
composeOptions {
kotlinCompilerExtensionVersion = "1.3.0"
}
然后就可以正常的运转了。由于Android由Java向Kotlin过渡,所以存在很多的版别兼容的问题,这些问题让开发者比较头疼,所以遇到问题一定要多上网查查。