获取“以下类的超类型无法解析....未解析的超类型:org.junit.runners.model.Statement”构建错误

8xiog9wr  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(148)

我没有真正改变任何与JUnit相关的东西,我得到了一个构建错误,看起来像:
e:无法解析以下类的超类型。请确保类路径中具有所需的依赖项:class androidx.test.internal.runner.junit4.statement.UiThreadStatement,未解析的超类型:org.junit.runners.model.Statement添加-Xextended-compiler-checks参数可能会提供其他信息。
它在构建输出中出现了两次。我之前确实添加了lifecycle observer库,但我已经删除了它。我也已经执行了多次clean -> rebuild -> make project和invalidate caches,但它仍然不起作用
以下是我的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'
}

字符串

mxg2im7a

mxg2im7a1#

不是一个令人满意的答案,但我想我找到了我的问题的罪魁祸首。在我的项目上做了一些git reset --hard之后,我找到了导致错误的提交。这是一个包含应用程序build.gradle中库更新的提交。我记得更新它们是因为我在构建时收到了一个奇怪的警告,它一直说我需要使用compileSdk 34,而我已经在使用它。认为这是因为我的“过时”的库,我更新了每一个显示它们更新的库。
在发现这一点后,我将我的项目重置为错误提交之前的提交,并添加了我在错误提交中所做的更改,因为我并不真的想首先更新我的库,所以我忽略了这些更改。现在应用程序可以正常构建。现在,我不知道在这种情况下推送更改的过程

相关问题