android - java.lang.IllegalStateException:找不到函数 androidx.compose.internal.restartableFunctionInstance
问题描述
当我尝试运行应用程序时,出现以下错误
"java.lang.IllegalStateException: Function not found androidx.compose.internal.restartableFunctionInstance"
和以下警告:
C:\Users\amr\.gradle\caches\transforms-2\files-2.1\29795ea219aedbe5401209deaa0aa414\jetified-kotlin-stdlib-jdk7-1.3.60-eap-25.jar: Runtime JAR file has version 1.3 which is older than required for API version 1.4
这是我在活动中的代码:
class MainActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle ? ) {
super.onCreate(savedInstanceState)
setContent {
Text("Hello World")
}
}
}
我正在使用 android studio 4.2 canary 2
这是完整的build.gradle
文件”
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.myfirstCompse"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
compose true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
composeOptions {
kotlinCompilerExtensionVersion "0.1.0-dev09"
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.ui:ui-framework:0.1.0-dev09'
implementation 'androidx.ui:ui-tooling:0.1.0-dev09'
implementation 'androidx.ui:ui-layout:0.1.0-dev09'
implementation 'androidx.ui:ui-material:0.1.0-dev09'
}
更新:当我将依赖版本更改为 dev09 并compileOptions
按照文档建议添加块时
composeOptions {
kotlinCompilerExtensionVersion "0.1.0-dev09"
}
它产生了以下错误:
e: java.util.NoSuchElementException: Collection contains no element matching the predicate.
解决方案
添加kotlinCompilerVersion = "1.3.70-dev-withExperimentalGoogleExtensions-20200424"
到您的composeOptions
闭包中:
composeOptions {
kotlinCompilerVersion = "1.3.70-dev-withExperimentalGoogleExtensions-20200424"
kotlinCompilerExtensionVersion "0.1.0-dev09"
}
你肯定需要这个;我不确定它是否会清除这个特定的错误。
您可能希望检查您在项目级build.gradle
文件中使用的 Kotlin 版本。1.3.70
是一个已知的安全版本(它与我的代码片段中的编译器插件版本匹配)。
推荐阅读
- javascript - 在 jsx 对象内插入 html 标签以进行映射
- java - 使用存储在数据库中的 ViewFlipper 滑动图像
- visual-studio - 无法通过 Visual Studio 2019 和 TFS 2018 的流程模板编辑器添加转换链接
- java - Java 处理程序如何在不发送 onUserInteraction 方法的情况下执行意图
- apostrophe-cms - 在撇号页面中显示撇号小部件
- azure-cosmosdb - 使用 microsoft azure documentdb api 连接到 cosmos db 导致错误请求错误
- docker - Docker“无效的引用格式:存储库名称必须小写”
- angular - 如何在 Angular 中创建表并搜索该表?
- python - 有什么方法可以在python中将路径附加到环境变量'PATH'
- swift - 如何从 NSDocument 的 read 方法中获取数据