gpt4 book ai didi

android - java.lang.NoClassDefFoundError : kotlin. jvm.internal.Intrinsics - newApplication

转载 作者:行者123 更新时间:2023-11-29 02:33:44 27 4
gpt4 key购买 nike

问题

我只是想将自定义 AndroidJUnitRunner 类从 Java 转换为 Kotlin。

代码

CustomTestRunner.java

public class CustomTestRunner extends AndroidJUnitRunner {
@Override
public Application newApplication(ClassLoader cl, String className, Context context) throws IllegalAccessException,
ClassNotFoundException, InstantiationException {
return super.newApplication(cl, TestApp.class.getName(), context);
}
}

CustomTestRunner.kt -(导致错误 - 请参阅下面的堆栈跟踪)

class CustomTestRunner : AndroidJUnitRunner() {
override fun newApplication(cl: ClassLoader, className: String, context: Context): Application {
return super.newApplication(cl, TestApp::class.java.name, context)
}
}

build.gradle

android {
defaultConfig {
testInstrumentationRunner "<>.CustomTestRunner"
}
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:1.2.0"
androidTestCompile "org.jetbrains.kotlin:kotlin-stdlib:1.2.0"
}

错误

D/AndroidRuntime( 4948): Shutting down VM
E/AndroidRuntime( 4959): FATAL EXCEPTION: main
E/AndroidRuntime( 4959): Process: <>.debug, PID: 4959
E/AndroidRuntime( 4959): java.lang.NoClassDefFoundError: kotlin.jvm.internal.Intrinsics
E/AndroidRuntime( 4959): at <>.newApplication(CustomTestRunner.kt)
E/AndroidRuntime( 4959): at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
E/AndroidRuntime( 4959): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4317)
E/AndroidRuntime( 4959): at android.app.ActivityThread.access$1500(ActivityThread.java:135)
E/AndroidRuntime( 4959): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
E/AndroidRuntime( 4959): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 4959): at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 4959): at android.app.ActivityThread.main(ActivityThread.java:5017)
E/AndroidRuntime( 4959): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 4959): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 4959): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
E/AndroidRuntime( 4959): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E/AndroidRuntime( 4959): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 2870): Error in app <>.debug running instrumentation ComponentInfo{<>.debug.test/<>.CustomTestRunner}:

最佳答案

你可能缺少类路径依赖:

buildscript {
. . .
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.20"
}
}

关于android - java.lang.NoClassDefFoundError : kotlin. jvm.internal.Intrinsics - newApplication,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48193132/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com