0

My build.gradle sourceset is defined like this:

sourceSets{

        test.root 'src/test/javaTest'
        test.java.srcDirs 'src/test/'
        androidTest.java.srcDirs 'src/test/java'
        androidTest.root 'src/test'
}

other setting is copied from https://github.com/android/testing-samples . then I tried to run the unit test, it gave compile error. androidx.test.ext.junit.runners does not exist ; Then I tried all methoed mentioned on this question(AndroidJUnit4.class is deprecated: How to use androidx.test.ext.junit.runners.AndroidJUnit4?), but none af them work. So what's problem with the AndroidUnitTest. Please help me . thank you!

all of my gradle.build like this:

//Top-level buildscript information
ext {
    kotlin_version = '1.3.71'
    rxjava_version = '3.0.6'

    androidxAnnotationVersion = "1.1.0"
    coreVersion = "1.3.0"
    extJUnitVersion = "1.1.2"
    runnerVersion = "1.3.0"
    hamcrestVersion = "1.3"
    truthVersion = "1.0.1"
}

buildscript {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.0.1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.71"

    }
}

repositories {
    google()
    jcenter()
    maven { url "https://jitpack.io" }
}


apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 30
    defaultConfig {
        targetSdkVersion 30
        minSdkVersion 26
        ndk {
            ldLibs 'log'
            abiFilters 'arm64-v8a', 'armeabi-v7a'
        }
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            res.srcDirs = ['res']
            aidl.srcDirs = ['aidl']
            jni.srcDirs = ['jni']
            jniLibs.srcDirs = ['build\\intermediates\\ndkBuild']
            assets.srcDirs = ['assets']
        }

//        androidTest.setRoot('./src/test')
//        androidTest.setRoot('./')
        test.root 'src/test/javaTest'
        test.java.srcDirs 'src/test/'
        androidTest.java.srcDirs 'src/test/java'
        androidTest.root 'src/test'
//        androidTest {
//            manifest.srcFile './AndroidManifest.xml'
//            java.srcDirs = ['./src/test/java']
//        }
    }
    externalNativeBuild {
        ndkBuild {
            path file("jni\\Android.mk")
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    def filePrivateProperties = file("./jks/platform.properties")
    if (filePrivateProperties.exists()) {
        signingConfigs {
            android {
                Properties propsPrivate = new Properties()
                propsPrivate.load(new FileInputStream(filePrivateProperties))

                storeFile file(propsPrivate['key.store'])
                keyAlias propsPrivate['key.alias']
                storePassword propsPrivate['key.store.password']
                keyPassword propsPrivate['key.alias.password']
            }
        }
    }
    buildTypes {
        debug {
            //applicationIdSuffix ".debug"
            if (filePrivateProperties.exists()) {
                signingConfig signingConfigs.android
            }
        }

        release {
            if (filePrivateProperties.exists()) {
                signingConfig signingConfigs.android
            }
            minifyEnabled true
            zipAlignEnabled true
            shrinkResources false
//            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), '../proguard.flags'
        }
    }
    ndkVersion '21.3.6528147'


}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//    implementation 'com.github.princekin-f:EasyFloat:1.3.3'     //
    implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.preference:preference:1.1.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
    androidTestImplementation 'junit:junit:4.12'
    compileOnly "org.projectlombok:lombok:1.18.12"
    annotationProcessor 'org.projectlombok:lombok:1.18.12'
    implementation "io.reactivex.rxjava3:rxjava:$rxjava_version"


    androidTestImplementation 'androidx.test:core:' + rootProject.coreVersion;
    androidTestImplementation 'androidx.test.ext:junit:' + rootProject.extJUnitVersion;
    androidTestImplementation 'androidx.test:runner:' + rootProject.runnerVersion;
    androidTestImplementation 'com.google.truth:truth:' + rootProject.truthVersion
}

ene
  • 257
  • 1
  • 8

0 Answers0