提问人:rminaj 提问时间:10/26/2023 最后编辑:rminaj 更新时间:10/27/2023 访问量:50
获取“无法解析以下类的超类型...”。未解析的超类型:org.junit.runners.model.Statement“构建错误
Getting a "Supertypes of the following classes cannot be resolved.... unresolved supertypes: org.junit.runners.model.Statement" build error
问:
我没有真正更改与 JUnit 相关的任何内容,并且我收到一个构建错误,如下所示:
e:无法解析以下类的超类型。请使 确保您在类路径中具有所需的依赖项: 类 androidx.test.internal.runner.junit4.statement.UiThreadStatement, 未解析的超类型:org.junit.runners.model.Statement 添加 -Xextended-compiler-checks 参数可能会提供其他信息。
它在构建输出中出现两次。我之前确实添加了 lifecycleobserver 库,但我已经删除了它。我还做了多次干净的 -> 重建 -> make project 并使缓存失效,但它仍然不起作用
这是我的build.gradle(app),如果它有帮助的话:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs.kotlin'
id 'kotlin-parcelize'
}
android {
namespace "com.my.app"
compileSdk 34
defaultConfig {
applicationId "com.my.app"
minSdk 24
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
getByName("release") {
minifyEnabled false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
buildFeatures {
dataBinding = true
}
testOptions {
unitTests.all {
useJUnitPlatform()
}
unitTests.returnDefaultValues = true
unitTests.includeAndroidResources = true
}
configurations {
debugImplementation.exclude group: "junit", module: "junit"
}
}
dependencies {
implementation "androidx.core:core-ktx:1.12.0"
implementation "androidx.appcompat:appcompat:1.6.1"
implementation "com.google.android.material:material:1.10.0"
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
implementation "androidx.preference:preference-ktx:1.2.1"
//image processing
implementation "io.coil-kt:coil:1.1.0"
//line chart
implementation "com.github.PhilJay:MPAndroidChart:v3.1.0"
//Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
//okhttp
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.10.0"))
implementation 'com.squareup.okhttp3:okhttp'
implementation 'com.squareup.okhttp3:logging-interceptor'
implementation 'com.google.firebase:firebase-crashlytics-buildtools:2.9.9'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
//Coroutines
def arch_version = '2.6.2'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$arch_version"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$arch_version"
//for viewModels
implementation "androidx.activity:activity-ktx:1.8.0"
implementation "androidx.fragment:fragment-ktx:1.6.1"
//multidex
def multidex_version = "2.0.1"
implementation "androidx.multidex:multidex:$multidex_version"
//room
def roomVersion = '2.6.0'
def lifecycleVersion = '2.6.2'
def coroutinesVersion = '1.6.4'
// Room components
implementation "androidx.room:room-ktx:$roomVersion"
kapt "androidx.room:room-compiler:$roomVersion"
androidTestImplementation "androidx.room:room-testing:$roomVersion"
// Lifecycle components
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
// Kotlin Coroutines
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"
//navigation
implementation "androidx.navigation:navigation-fragment-ktx:$navigation_ver"
implementation "androidx.navigation:navigation-ui-ktx:$navigation_ver"
//reflection
implementation "org.jetbrains.kotlin:kotlin-reflect:1.9.0"
//socket.io
implementation('io.socket:socket.io-client:0.8.3') {
exclude group: 'org.json', module: 'json'
}
//image loading
implementation 'com.github.bumptech.glide:glide:4.15.1'
implementation 'androidx.test:core:1.5.0'
testImplementation "junit:junit:4.13.2"
testImplementation 'org.hamcrest:hamcrest-all:1.3'
testImplementation 'androidx.arch.core:core-testing:2.2.0'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1'
testImplementation 'com.google.truth:truth:1.1.5'
testImplementation 'androidx.test.ext:junit-ktx:1.1.5'
debugImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation "androidx.test.ext:junit:1.1.5"
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.3.0-alpha04'
debugImplementation 'androidx.fragment:fragment-testing:1.6.1'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.12'
}
答:
0赞
rminaj
10/27/2023
#1
不是一个令人满意的答案,但我想我找到了问题的罪魁祸首。在我的项目上做了一些事情后,我找到了导致错误的提交。这是一个提交,包括对应用程序 build.gradle 中库的更新。我记得更新它们是因为我在构建时收到一个奇怪的警告,它一直说我需要在我已经使用它时使用。我以为这是因为我的“过时”库,我更新了每一个显示它们已更新的库。git reset --hard
compileSdk 34
发现这一点后,我将我的项目重置为错误的提交之前的提交,并添加了我在错误的提交中所做的更改,因为我一开始并不想更新我的库,所以我忽略了这些。现在,应用程序已正确构建。现在,我不知道在这种情况下推送我的更改的过程
评论