AssertionError:根包必须被初始化
我在Android Studio中的另一台计算机上打开我的Kotlin项目,并在事件日志中遇到错误:
AssertionError:根包必须被初始化
Root package must be initialized java.lang.AssertionError: Root package must be initialized at org.jetbrains.kotlin.resolve.lazy.ResolveSession.getAllPackages(ResolveSession.java:329) at org.jetbrains.kotlin.resolve.lazy.ResolveSession.forceResolveAll(ResolveSession.java:350) at org.jetbrains.kotlin.idea.references.BuiltInsReferenceResolver$2.run(BuiltInsReferenceResolver.java:121) at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:872) at org.jetbrains.kotlin.idea.references.BuiltInsReferenceResolver$3.run(BuiltInsReferenceResolver.java:141) at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:400) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) at org.jetbrains.ide.PooledThreadExecutor$1$1.run(PooledThreadExecutor.java:56)
项目主体结构:
的build.gradle
apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { applicationId "taskmoney" minSdkVersion 15 targetSdkVersion 22 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } sourceSets { main.java.srcDirs += 'src/main/kotlin' local.java.srcDirs += 'src/local/kotlin' } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) //dependencies list } buildscript { ext.kotlin_version = '0.12.1230' repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.2.3' classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } }
所以,无法打开任何.kt文件。
猜猜我错过了一些简单的…谢谢
我相信这是因为你的Android Studio IDE的版本。 我在使用1.2时遇到了同样的问题,升级到1.5后问题解决了。