I have the following Gradle configuration in my Android Project:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
apply plugin: 'com.android.application'
dependencies {
repositories {
jcenter()
google()
}
compile fileTree(include: '*.jar', dir: 'libs')
compile 'com.android.support:support-v4:25.4.0'
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0'
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
buildTypes {
debug {
debuggable true
applicationIdSuffix ".debug"
}
}
defaultConfig {
jackOptions {
enabled true
}
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
I want to start making UI tests so I recorded an espresso test via the Android Studio recording functionality. Afterwards, when saving the test class file, i noticed some of the imports were no resolved.
Error:(17, 8) The import org.junit cannot be resolved
Error:(19, 15) The import android.support.test cannot be resolved
As you can see, I add the junit dependency directly, so why doesn't android studio or gradle see the junit library?
This is my dep tree:
androidTestCompile - Classpath for compiling the androidTest sources.
+--- junit:junit:4.12
| \--- org.hamcrest:hamcrest-core:1.3
\--- com.android.support.test.espresso:espresso-core:3.0.0
+--- com.android.support.test:runner:1.0.0
| +--- com.android.support:support-annotations:25.4.0
| +--- junit:junit:4.12 (*)
| \--- net.sf.kxml:kxml2:2.3.0
+--- com.android.support.test:rules:1.0.0
| \--- com.android.support.test:runner:1.0.0 (*)
+--- com.android.support.test.espresso:espresso-idling-resource:3.0.0
+--- com.squareup:javawriter:2.1.1
+--- javax.inject:javax.inject:1
+--- org.hamcrest:hamcrest-library:1.3
| \--- org.hamcrest:hamcrest-core:1.3
+--- org.hamcrest:hamcrest-integration:1.3
| \--- org.hamcrest:hamcrest-library:1.3 (*)
\--- com.google.code.findbugs:jsr305:2.0.1
And my source folder is organized like this:
└── src
├── androidTest
│ └── java
│ └── pt
│ └── joaomneto
│ └── titancompanion
│ └── (expresso tests source code)
└── pt
└── joaomneto
└── titancompanion
└── (app source code)
Thanks for your help