1. 程式人生 > >關於 Unable to load class 'kotlin.collections.CollectionsKT' 或Error:Could not initialize class or報錯記錄

關於 Unable to load class 'kotlin.collections.CollectionsKT' 或Error:Could not initialize class or報錯記錄

關於

Error:Could not initialize class 

org.jetbrains.kotlin.kapt.idea.KaptModelBuilderService

或者

Unable to load class 'kotlin.collections.CollectionsKT' 報錯解決問題記錄。

匯入別人的專案的時候遇到了 Unable to load class 'kotlin.collections.CollectionsKT' 的問題,然後百度跳到了stack overflow 網站,順著別人的思路順利的解決了問題,在此記錄下,給後來的遇到此坑的人一些提示。

放上鍊接地址:

在留言區,我看到了這樣一段描述,英文不好的同學自行翻譯也能看懂大概。

I had the same problem when I was trying out a sample project on GitHub. I had no idea why this is happening, later I realised that the gradle version in gradle-wrapper.properties and the gradle version installed on my machine are different. So I just updated the gradle-wrapper.properties to take latest gradle version installed. Everything built smoothly.

You may also have a mismatch in gradle build tools version in build.gradle file. Update that as well if required. This is how my build.gradle look like after updating

以上是給我啟發的原文內容,簡單點說就是 gradle-wrapper.properties 中Grdle的版本和 gradle 版本不一致導致的問題,這麼說有些繞口,下面看圖指出具體是那兩個地方。分別展示在兩種目錄結構下的位置



這個是我新建的一個正常的project,查看了兩處地方的gradle版本配置,然後看下錯誤的對比。


可以看到跟我正常的專案的Gradle配置確實不一樣,就老老實實的改成一樣的在看看效果


結果驚奇的發現,居然編譯通過了,有點小興奮,於是乎在這裡做下記錄,以便後來的同學能給啟發的靈感。