【问题标题】:IllegalStateException: function = <anonymous>, count = 3, index = 3IllegalStateException:函数 = <匿名>,计数 = 3,索引 = 3
【发布时间】:2021-08-08 09:10:10
【问题描述】:

直到昨天一切都很好。今天打开系统突然报错:

java.lang.IllegalStateException: function = <anonymous>, count = 3, index = 3

在运行我的项目时出现“内部编译器错误”。

我尝试更新我的 gradle 版本和 gradle 插件版本,以及我使用的依赖项,但没有成功。

我该如何解决这个问题?

这些是我使用的依赖项:

    def lifecycle_version = "2.3.1"

    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation "androidx.drawerlayout:drawerlayout:1.1.1"
    implementation "androidx.navigation:navigation-fragment-ktx:2.3.5"
    implementation "androidx.navigation:navigation-ui-ktx:2.3.5"
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'com.shawnlin:number-picker:2.4.11'
    implementation 'com.karumi:dexter:6.2.1'
    implementation 'com.github.IslamKhSh:CardSlider:1.0.1'
    implementation 'com.intuit.sdp:sdp-android:1.0.6'
    implementation 'com.intuit.ssp:ssp-android:1.0.6'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
    implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
    implementation 'com.google.android.gms:play-services-auth:19.0.0'
    implementation 'com.google.android.gms:play-services-auth-api-phone:17.5.0'
    implementation 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:3.0.0-RC2'
    // Lottie dependency
    implementation "com.airbnb.android:lottie:3.7.0"

    //Autostart settings open
    implementation 'com.thelittlefireman:AppKillerManager:2.1.1'

    // Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'

    // JSON Parsing
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.squareup.retrofit2:converter-gson:2.1.0'

    implementation 'com.android.support:multidex:1.0.3'

    implementation 'androidx.cardview:cardview:1.0.0'

    // ViewModel
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
    // LiveData
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"

    implementation "androidx.core:core-ktx:1.3.2"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.31"

    implementation "org.koin:koin-core:2.2.2"
    implementation "org.koin:koin-androidx-viewmodel:2.2.2"
    implementation "androidx.datastore:datastore-preferences:1.0.0-beta01"
    implementation 'com.github.pwittchen:swipe-rx2:0.3.0'
    implementation "androidx.compose.material:material:1.0.0-beta06"
    implementation "androidx.compose.ui:ui-tooling:1.0.0-beta06"
    implementation "androidx.compose.ui:ui:1.0.0-beta07"
    implementation "androidx.constraintlayout:constraintlayout-compose:1.0.0-alpha06"
    implementation "androidx.navigation:navigation-compose:1.0.0-alpha10"
    implementation "androidx.activity:activity-compose:1.3.0-alpha08"
    implementation "androidx.compose.animation:animation:1.0.0-beta06"
    implementation "androidx.compose.animation:animation-core:1.0.0-beta07"
    implementation "androidx.ui:ui-framework:0.1.0-dev03"
    implementation "androidx.compose.runtime:runtime-livedata:1.0.0-beta06"
    implementation group: 'com.airbnb.android', name: 'lottie-compose', version: '1.0.0-beta03-1'

    testImplementation 'junit:junit:4.13.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

【问题讨论】:

  • 您能分享导致异常的代码吗?
  • 不知道是我的代码的哪一部分导致了它,因为日志没有说明任何内容。
  • 你试过清理然后重建你的项目吗?
  • 我自己也开始看到这个问题。奇怪。
  • 将所有撰写版本更新为 1.0.0-beta07 并导航到“androidx.navigation:navigation-compose:2.4.0-alpha01”

标签: android kotlin compiler-errors android-constraintlayout android-jetpack-compose


【解决方案1】:

如果我将撰写的所有实现降级为 beta6 并将撰写导航到 1.0.0-alpha08,则对我有用。或者你应该像这样在composeOptions(在build.gradle,应用模块)中将kotlinCompilerExtensionVersion更新为1.0.0-beta7

android {
    ...
    composeOptions {
         val composeVersion by extra("1.0.0-beta07")
         kotlinCompilerExtensionVersion = composeVersion
    }
    ...
}

此样本位于build.gradle.kts

【讨论】:

  • 工作。谢谢!
  • 在将 agp 升级到 7.0.0-beta01 后也发生了这种情况。很遗憾无法升级到最新的 compose beta:/
  • 对我有用的是保留较新的版本,但将我的 kotlinCompilerExtensionVersion 更新为 1.0.0-beta07 就像这个答案建议的那样:stackoverflow.com/a/67629087/3692626
【解决方案2】:

在我的情况下,将 ConstraintLayout 版本从 1.0.0-alpha07 降级到 1.0.0-alpha06 有帮助。

implementation "androidx.constraintlayout:constraintlayout-compose:1.0.0-alpha06"

【讨论】:

    【解决方案3】:

    我能够通过将所有 compose 依赖项以及 kotlinCompilerExtensionVersion 升级到 1.0.0-beta07 来解决此问题。

    我也在使用 accompanist 库,它需要升级到版本“0.10.0”,该版本是为与 compose beta07 一起使用而构建的。

    【讨论】:

    • 这是关键,而不是恢复到旧版本。
    【解决方案4】:

    这发生在我将 androidx.navigation:navigation-compose 从 1.0 更新到 2.4 之后

    【讨论】:

      【解决方案5】:

      我自己也遇到过这个。两个问题依赖项是:

      • androidx.compose.ui:ui:1.0.0-beta07
      • androidx.activity:activity-compose:1.3.0-alpha08

      我将每个版本都回滚了一个版本,并且我正在重新构建:

      • androidx.compose.ui:ui:1.0.0-beta06
      • androidx.activity:activity-compose:1.3.0-alpha07

      【讨论】:

        【解决方案6】:

        尝试将“activity-compose”从“1.3.0-alpha08”降级为“1.3.0-alpha07”

        implementation "androidx.activity:activity-compose:1.3.0-alpha07"
        

        【讨论】:

          【解决方案7】:

          当我将用于图像加载的 Coil 版本更新到 0.11.0 时出现此问题。

          对我来说,解决方案是将所有 compose 依赖项升级到最新版本(在我的情况下为 1.0.0-beta08),为此,kotlinCompilerExtensionVersion 也必须更新到最新版本(在我的情况'1.5.10')

          【讨论】:

          • 升级一切也对我有用。
          【解决方案8】:

          对我来说,问题是accompanist-coil 我今天将其更新为0.10.0,由于这个错误,我将版本降级为0.6.2

          【讨论】:

            【解决方案9】:

            当我将 androidx.constraintlayout:constraintlayout-compose 更新为 1.0.0-alpha07(从 1.0.0-alpha06)时出现错误 并在我将所有依赖项更新到最新版本时消失:所有 androidx.compose.* 到 1.0.0-beta07,androidx.activity:activity-compose 到 1.3.0-alpha08 和 androidx.constraintlayout:constraintlayout-compose 到 1.0.0 -alpha07

            【讨论】:

              【解决方案10】:

              对我有用的是在 app build.gradle 文件中将 kotlinCompilerExtensionVersion 更改为版本“1.0.0-beta07”。

              【讨论】:

                【解决方案11】:

                compose_version "1.0.0-beta07" 需要 kotlinCompilerVersion 到 "1.4.32"。我的compose_version是“1.0.0-beta01”,所以我选择将constraintlayout-compose从“1.0.0-alpha07”降级为“1.0.0-alpha06”

                【讨论】:

                  【解决方案12】:

                  Compose Beta 07 引入了重大更改,因此为了解决这个问题,我必须将 Compose 更新到 1.0.0-beta07 和所有其他 -compose 库到最新的可能版本:

                  activity-compose:1.3.0-alpha08
                  navigation-compose:2.4.0-alpha01
                  hilt-navigation-compose:1.0.0-alpha02
                  etc...
                  

                  【讨论】:

                    猜你喜欢
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 2019-06-22
                    • 2014-09-16
                    • 1970-01-01
                    • 1970-01-01
                    • 2017-02-20
                    相关资源
                    最近更新 更多