I am unsure of what is causing this issue. There are no compile time errors in Android Studio. This only occurs when I run an android test:
Task :app:compileDebugAndroidTestKotlin FAILED
e: C:\Users\alexl\Documents\Speak-Easy\app\src\androidTest\java\com\spark\chat\screen\AuthenticationScreen.kt: (4, 25): Unresolved reference: BaseScreen
e: C:\Users\alexl\Documents\Speak-Easy\app\src\androidTest\java\com\spark\chat\screen\AuthenticationScreen.kt: (6, 30): Unresolved reference: BaseScreen
e: C:\Users\alexl\Documents\Speak-Easy\app\src\androidTest\java\com\spark\chat\screen\AuthenticationScreen.kt: (9, 9): Unresolved reference: checkHint
e: C:\Users\alexl\Documents\Speak-Easy\app\src\androidTest\java\com\spark\chat\screen\AuthenticationScreen.kt: (13, 9): Unresolved reference: checkHint
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugAndroidTestKotlin'.
> Compilation error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
App builds fine normally when not running androidTest. I have a module with the package name com.spark.common. App package name is com.spark.chat. Not sure if that has anything to do with it. In my android-library-module.gradle:
apply plugin: "com.android.library"
apply plugin: "org.jetbrains.kotlin.android"
android {
compileSdk DefaultConfig.compileSdk
defaultConfig {
minSdk DefaultConfig.minSdk
targetSdk DefaultConfig.targetSdk
versionCode DefaultConfig.versionCode
versionName DefaultConfig.versionName
testInstrumentationRunner DefaultConfig.testInstrumentationRunner
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation Lib.androidXCoreKotlin
implementation Lib.androidXAppCompat
implementation Lib.googleMaterial
implementation Lib.constraintLayout
testImplementation Lib.junit
androidTestImplementation Lib.androidXJunit
androidTestImplementation Lib.espresso
androidTestImplementation Lib.espressoIntents
androidTestImplementation Lib.androidXTruth
androidTestImplementation Lib.androidXRunner
androidTestImplementation Lib.androidXRules
}
In my common.build.gradle:
apply from: "$rootDir/android-library-build.gradle"
In my app.build.gradle:
apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
android {
compileSdk DefaultConfig.compileSdk
defaultConfig {
applicationId DefaultConfig.applicationId
minSdk DefaultConfig.minSdk
targetSdk DefaultConfig.targetSdk
versionCode DefaultConfig.versionCode
versionName DefaultConfig.versionName
testInstrumentationRunner DefaultConfig.testInstrumentationRunner
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation project(Modules.common)
implementation Lib.androidXCoreKotlin
implementation Lib.androidXAppCompat
implementation Lib.googleMaterial
implementation Lib.constraintLayout
testImplementation Lib.junit
androidTestImplementation Lib.androidXJunit
androidTestImplementation Lib.espresso
androidTestImplementation Lib.espressoIntents
androidTestImplementation Lib.androidXTruth
androidTestImplementation Lib.androidXRunner
androidTestImplementation Lib.androidXRules
}
In my buildSrc.build.gradle.kts:
import org.gradle.kotlin.dsl.`kotlin-dsl`
plugins {
`kotlin-dsl`
}
repositories {
mavenCentral()
}
Thank you!
CodePudding user response:
The issue was due to the BaseTest class being part of the androidTest directory in the common module.
Only files in the main directory get included in the build file. So the app module, when implementing the common project, will only get its main directory classes.
Solution is to move the classes to the main directory of the module.