【发布时间】:2016-12-06 01:52:56
【问题描述】:
我们的 android 应用程序的每第二次运行,我们都会遇到一个崩溃,上面写着
java.lang.NoClassDefFoundError: Failed resolution of: Lin/blahapp/xxx/BlahUtil
BlahUtil 是一个带有 @JvmStatic 注释的 kotlin 对象。我从 android app(All in java) 的其余部分调用这些静态方法。
我们使用 multidex 1.0.1。
我在 android studio 2.1.2 上,使用 JDK 7。
相关的gradle配置:
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
}
dexOptions {
incremental true
dexInProcess true
javaMaxHeapSize "10g"
preDexLibraries true
}
buildscript {
ext.kotlin_version = '1.0.3'
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin-android'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
}
追踪:
at in.blahapp.xxx.OurActivity
at android.app.Activity.performCreate(Activity.java:6251)
at ndroid.app.Instrumentation.callActivityOnCreate
at android.app.ActivityThread.performLaunchActivity
at android.app.ActivityThread.handleLaunchActivity
at android.app.ActivityThread.-wrap11
at android.app.ActivityThread$H.handleMessage
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "in.blahapp.xxx.BlahUtil" on path: DexPathList[[dex file ....
【问题讨论】:
-
这种情况总是发生还是仅在每第二次构建时发生(或者,在另一种变体中,仅在第一次干净构建时发生)?
-
通常不会在干净构建之后的第一次运行中发生。当我进行一些更改并再次运行时,第二次运行时崩溃。第三次运行。如果我再次进行更改,它会在下一次运行时立即崩溃。然后在运行之后......等等。
-
这听起来很像this bug。当 Kotlin 类在第一次干净编译时未找到(=删除)但出现在第二次增量构建时,我遇到了此错误的另一个变体。 google tracker上也有讨论过,结果是要等android gradle plugin 2.3发布了。这个问题使我无法在我的团队中引入 Kotlin,很遗憾,我没有任何建议可以与您分享。
-
只是好奇 - 你为什么要设置 javaMaxHeapSize "10g"?
-
我有同样的问题,但只发生在某些设备上。我构建和 .apk,安装后它在某些设备上完美运行,但在一些设备(所有版本 7.x)中崩溃,为 Kotlin 活动抛出异常 NoClassDefFoundError。
标签: android kotlin kotlin-android-extensions