后端内部错误:Jetpack compose 中 psi2ir 期间出现异常
Posted
技术标签:
【中文标题】后端内部错误:Jetpack compose 中 psi2ir 期间出现异常【英文标题】:Backend Internal error: Exception during psi2ir in Jetpack compose 【发布时间】:2021-09-08 15:02:42 【问题描述】:我在编译或代码生成期间收到此错误,我已设置 Jetpack Compose 依赖项并对其进行处理,我已经制作了一些 compose 组件并且预览是可见的,但在编译期间我遇到了此问题。
我正在使用 android Studio ArticFox
org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during psi2ir
File being compiled: (154,13) in /Users/vipulthawre/AndroidStudioProjects/tbappCompose/base-question-module/src/main/java/com/testbook/tbapp/base_question/MamcqPracticehtml.kt
The root cause java.lang.***Error was thrown at: java.base/java.lang.ClassLoader.defineClass1(Native Method)
null: KtBinaryExpression:
"<style type=\"text/css\"> \n" +
" body \n" +
" color: #1E2022;\n" +
" margin: 0px;\n" +
" \n" +
"\n" +
"
脚本位于该文件中,如下所示
private fun getStyle(): String
val styleCss =
"<style type=\"text/css\"> \n" + " body \n" + " color: #1E2022;\n" + " margin: 0px;\n" + " \n" + "\n" + " .question \n" + " padding: 16px;\n" + " font-size: 16px;\n" + " border-bottom: 1px solid " + dividerColor + ";\n" + " background: #FFFFFF;\n" + " \n" + "\n" + " .option \n" + " padding: 0;\n" + " margin-left:8px; margin-right:8px;\n" + " \n" + "\n" + " .option li \n" + " box-sizing: border-box;\n" + " font-size: 16px;\n" + " width: calc(100% - 38px);\n" + " display: table;\n" + " border: 1px solid transparent;\n" + " border-bottom-color: " + dividerColor + ";\n" + " list-style: none;\n" + " padding: 18px;\n" + " margin-top: 5px;\n" + " margin-bottom: 5px;\n" + " border-radius: 2px;\n" + " background: #FFFFFF;\n" + " \n" + "\n" + " .view-solution-div \n" + " box-sizing: border-box;\n" + " font-size: 16px;\n" + " width: 100%;\n" + " display: table;\n" + " border: 1px solid transparent;\n" + " border-bottom: 1px solid " + dividerColor + ";\n" + " list-style: none;\n" + " padding: 18px;\n" + " border-radius: 2px;\n" + " background: #FFFFFF;\n" + " \n" + "\n" + " .solution \n" + " position: relative;\n" + " padding: 16px;\n" + " border-bottom: 1px solid " + dividerColor + ";\n" + " border-radius: 3px;\n" + " background: #FFFFFF;\n" + " overflow: hidden;\n" + " \n" + "\n" + " .solution_overlay \n" + " position: absolute;\n" + " left: 0;\n" + " right: 0;\n" + " top: 0;\n" + " bottom: 0;\n" + " margin: auto;\n" + " background: rgba(255, 255, 255, 0.7);\n" + " text-align: center;\n" + " font-weight: bold;\n" + " color: #222;\n" + " \n" + "\n" + " .solution_overlay p \n" + " position: absolute;\n" + " padding: 16px;\n" + " left: 0;\n" + " right: 0;\n" + " margin: 0;\n" + " top: 50% !important;\n" + " -webkit-transform: translate(0, -50%);\n" + " transform: translate(0, -50%);\n" + " \n" + "\n" + " #solution \n" + " border-bottom: 1px solid " + dividerColor + ";\n" + " position: relative;\n" + " padding: 8px;\n" + " background: #FFFFFF;\n" + " overflow: hidden;\n" + " margin-top: 16px;\n" + " margin-bottom:20px;" + " \n" + "\n" + " .blurred \n" + " text-shadow: 0 0 5px rgba(0, 0, 0, 0.5);\n" + " color: transparent;\n" + " \n" + "\n" + " .numerical \n" + " width: 100%;\n" + " padding-top: 30px;\n" + " padding-bottom: 30px;\n" + " margin-bottom: 70px;\n" + " margin-top: 50px;\n" + " border-bottom: 1px solid " + dividerColor + ";\n" + " border-radius: 1px;\n" + " background: #FFFFFF;\n" + " display: table;\n" + " box-sizing: border-box;\n" + " \n" + "\n" + " #ans_div \n" + " padding-left: 20px !important;\n" + " \n" + "\n" + " .numerical input \n" + " background: #fff;\n" + " border-bottom: 1px solid #A9A9A9;\n" + " font-style: normal !important;\n" + " outline: none !important;\n" + " \n" + "\n" + " .numerical button \n" + " background: #fff;\n" + " border: 0px !important;\n" + " \n" + "\n" + " .numerical input:active, .numerical input:focus \n" + " border-bottom: 2px solid #1FBAD6 !important;\n" + " \n" + "\n" + " .wrongNumerical \n" + " background: #ffe5e5 !important;\n" + " \n" + "\n" + " .correctNumerical \n" + " background: #e5ffe5 !important;\n" + " \n" + "\n" + " .correctOption \n" + " border-radius: 1px!important;\n" + " background: rgba(139, 213, 139, 0.25)!important;\n" + " border: 1px solid rgba(110, 194, 110, 0.85)!important;\n" + " \n" + "\n" + " .correctNumerical \n" + " border-radius: 1px;\n" + " background: rgba(139, 213, 139, 0.25);\n" + " border: 1px solid rgba(110, 194, 110, 0.85);\n" + " \n" + "\n" + " .markedOption \n" + " border-radius: 1px !important;\n" + " background: rgba(170, 216, 225, 0.25) !important;\n" + " border: 1px solid rgba(42, 160, 182, 0.85) !important;\n" + " \n" + "\n" + " .wrongOption \n" + " border-radius: 1px!important;\n" + " background: rgba(254, 159, 159, 0.25)!important;\n" + " border: 1px solid rgba(231, 67, 67, 0.85)!important;\n" + " \n" + "\n" + " input[placeholder] \n" + " font-style: italic;\n" + " \n" + "\n" + " input::-webkit-outer-spin-button, input::-webkit-inner-spin-button \n" + " -webkit-appearance: none;\n" + " margin: 0;\n" + " \n" + "\n" + " p \n" + " margin: 0;\n" + " padding: 0;\n" + " line-height: 23px;\n" + " font-family: 'roboto';\n" + " font-size: 16px;\n" + " color: #1E2022 !important;\n" + " \n" + "\n" + " span \n" + " margin: 0;\n" + " padding: 0;\n" + " line-height: 23px;\n" + " font-family: 'roboto';\n" + " font-size: 16px;\n" + " color: #1E2022 !important;\n" + " \n" + "\n" + " img \n" + " max-width: 100% !important;\n" + " height: auto !important;\n" + " \n" + "\n" + " .MathJax_SVG svg > g, .MathJax_SVG_Display svg > g \n" + " fill: #1E2022 !important;\n" + " stroke: #1E2022 !important\n" + " \n" + "\n" + " .switch \n" + " position: relative;\n" + " display: inline-block;\n" + " width: 35px;\n" + " height: 14px;\n" + " vertical-align: middle;\n" + " margin-left: 10px;\n" + " -webkit-tap-highlight-color: transparent;\n" + " \n" + "\n" + " .switch input \n" + " display: none;\n" + " \n" + "\n" + " .slider \n" + " position: absolute;\n" + " cursor: pointer;\n" + " top: 0;\n" + " left: 0;\n" + " right: 0;\n" + " bottom: 0;\n" + " background-color: rgba(17, 171, 213, 0.13);\n" + " -webkit-transition: .2s;\n" + " transition: .2s;\n" + " \n" + "\n" + " .slider:before \n" + " position: absolute;\n" + " content: \"\";\n" + " height: 20px;\n" + " width: 20px;\n" + " left: -1px;\n" + " bottom: -3px;\n" + " background-color: #A5A8B6;\n" + " -webkit-transition: .2s;\n" + " transition: .2s;\n" + " \n" + "\n" + " input:focus + .slider \n" + " box-shadow: 0 0 1px #2196F3;\n" + " \n" + "\n" + " input:checked + .slider:before \n" + " -webkit-transform: translateX(15px);\n" + " transform: translateX(15px);\n" + " background-color: #1EB6D2;\n" + " \n" + "\n" + " /* Rounded sliders */\n" + " .slider.round \n" + " border-radius: 34px;\n" + " \n" + "\n" + " .slider.round:before \n" + " border-radius: 50%;\n" + " \n" + "\n" + " .missedOption \n" + " border-radius: 1px!important;\n" + " background: rgba(125, 193, 125, 0.1)!important;\n" + " border: 1.5px dashed rgba(0, 200, 0, 0.85)!important;\n" + " \n" + "\n" + " .markedOption \n" + " border-radius: 1px !important;\n" + " background: rgba(170, 216, 225, 0.25) !important;\n" + " border: 1px solid rgba(42, 160, 182, 0.85) !important;\n" + " \n" + "\n" + " .btn \n" + " display: inline-block;\n" + " margin: 8px;\n" + " font-weight: 400;\n" + " text-align: center;\n" + " vertical-align: middle;\n" + " touch-action: manipulation;\n" + " cursor: pointer;\n" + " border: 1px solid #000000;\n" + " white-space: nowrap;\n" + " padding: 6px 12px;\n" + " font-size: 14px;\n" + " line-height: 1.42857143;\n" + " border-radius: 0;\n" + " -webkit-user-select: none;\n" + " -moz-user-select: none;\n" + " -ms-user-select: none;\n" + " user-select: none;\n" + " \n" + " .btn-primary \n" + " border: 1px solid transparent;\n" + " color: #fff;\n" + " background-color: #1fbad6;\n" + " border-color: #1fbad6;\n" + " border-radius: 4px;\n" + " box-shadow: 1px 1px 3px RGBA(0, 0, 0, 0.2)\n" + " " + " .multi-info \n" + " color: #CDCDCD!important;\n" + " font-size: 14px!important;\n" + " " + " .missed-answer-text \n" + " position: absolute;\n" + " bottom:0;\n" + " right:0;\n" + " font-size: 8px;\n" + " background-color: #20b24e;\n" + " color: white!important; \n" + " padding-top: 0px;\n" + " padding-bottom: 0px;\n" + " line-height: 16px;\n" + " padding-left: 10px; \n" + " padding-right: 10px; \n" + " \n" + " .icon-img\n" + " position: relative;\n" + " float: right;\n" + " clear: both;\n" +
// " top:-10px;\n" +
" " + "\n" + " </style>"
return styleCss
图片:
我的模块.gradle:
plugins
id 'com.android.library'
id 'kotlin-android'
android
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
buildFeatures
// Enables Jetpack Compose for this module
compose true
buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
compileOptions
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
kotlinOptions
jvmTarget = '1.8'
useIR = true
composeOptions
kotlinCompilerVersion = "1.5.10"
kotlinCompilerExtensionVersion = "1.0.0-beta09"
dependencies
implementation project(":resource-module")
implementation project(":constants-module")
implementation project(":prefs-module")
implementation project(":network-module")
implementation project(path: ':models-module')
implementation project(":base-ui-module")
api 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
api 'com.google.android.material:material:1.3.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
api("androidx.compose.ui:ui:1.0.0-beta09")
// Tooling support (Previews, etc.)
api("androidx.compose.ui:ui-tooling:1.0.0-beta09")
// Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
api("androidx.compose.foundation:foundation:1.0.0-beta09")
// Material Design
api("androidx.compose.material:material:1.0.0-beta09")
// Material design icons
api("androidx.compose.material:material-icons-core:1.0.0-beta09")
api("androidx.compose.material:material-icons-extended:1.0.0-beta09")
// Integration with observables
api("androidx.compose.runtime:runtime-livedata:1.0.0-beta09")
api("androidx.compose.runtime:runtime-rxjava2:1.0.0-beta09")
api("androidx.compose.compiler:compiler:1.0.0-beta09")
api 'androidx.activity:activity-compose:1.3.0-beta02'
// UI Tests
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.0.0-beta09")
【问题讨论】:
我遇到了同样的问题,但我认为这与 Jetpack Compose 无关。当我将 Kotlin 编译器更新到 1.5.20 后,这个问题也开始发生在我的项目中。 1.4.32 一切正常。我没有在我的项目中使用 Jetpack Compose,我使用的是 Android Studio (4.2.2) 的稳定版本 【参考方案1】:我遇到了同样的问题 Invalidate Caches / Restart in Android Studio 对我有用
【讨论】:
【参考方案2】:Build > Clean Project 解决了我的问题
【讨论】:
【参考方案3】:对我来说,真正的问题隐藏在顶层构建错误中:
点击它,它应该会显示一个带有堆栈跟踪的更长的错误消息。
【讨论】:
任何分辨率?【参考方案4】:在将 Kotlin 版本从 1.5.31 更新到 1.6.0 后,我的构建发生了这种情况。恢复构建完成
【讨论】:
【参考方案5】:出现此问题的原因是 styleCss 字符串是 100 多个小字符串的集合,这些小字符串被附加在一起以创建单个字符串,但由于 Kotlin 的堆栈大小从 1.5.0 版本开始减少,它给出了***
错误。这个问题可以通过使用multiLineStringLiteral of Kotlin 来解决。
val styleCss =
"""<style type=\"text/css\">
body
color: #1E2022;
margin: 0px;
"""
我已经使用这种方式解决了上述问题。你可以阅读更多关于这个here的信息。
【讨论】:
【参考方案6】:我遇到了同样的错误。
截至目前,无效缓存/重启可能会解决这个问题,所以试试吧
前往
文件 -> 使缓存无效/重新启动
【讨论】:
以上是关于后端内部错误:Jetpack compose 中 psi2ir 期间出现异常的主要内容,如果未能解决你的问题,请参考以下文章
谷歌内部学习分享 Android Jetpack Compose开发应用指南,赶紧码住
谷歌内部学习分享 Android Jetpack Compose开发应用指南,赶紧码住
Jetpack Compose 的 3 大错误(不惜一切代价避免)