'Backend Internal error: Exception during psi2ir in Jetpack compose

I am getting this error during compilation or code generation, I have set the Jetpack Compose dependencies and working on it, I have made some compose components and previews are visible but during compilation I am getting this issue.

I am using 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.StackOverflowError 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" + 
" 

and the script is in that file as follows

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
}

Image:

enter image description here

my module.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")
}


Solution 1:[1]

I was having same issue Invalidate Caches / Restart in Android Studio worked for me

Solution 2:[2]

Build > Clean Project fixed my problem

Solution 3:[3]

For me, the real issue was hidden in the top level build error:

enter image description here

Click that and it should reveal a lengthier error message with a stack trace.

Solution 4:[4]

This occurred to my build after updating Kotlin version from 1.5.31 to 1.6.0. Reverting back the build finished

Solution 5:[5]

This issue is occurring cause the styleCss string is a collection of more than 100+ small strings which are being appended together to create a single string but due to the reduction of stack size of Kotlin from version 1.5.0, it is giving a Stackoverflow Error. This issue can be solved by using multiLineStringLiteral of Kotlin something like this.

val styleCss =
            """<style type=\"text/css\">
        body {
            color: #1E2022;
            margin: 0px;
        }"""

I have solved the above issue using this way. You can read more about this here.

Solution 6:[6]

In my case it was kodein import issue.

For this override val kodein by kodein()

We need to import import org.kodein.di.android.x.kodein

Solution 7:[7]

I faced the same error.

As of now, invalidate caches / Restart might solve this, so try it

Go to

File -> Invalidate Caches / Restart

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stan
Solution 2 Burak Tunta?
Solution 3 Kes Walker
Solution 4 delicatesan
Solution 5 ritwikshanker
Solution 6 shaby
Solution 7 Ayodan