-
Notifications
You must be signed in to change notification settings - Fork 183
/
Copy pathbuild.workaround-missing-resource.gradle
23 lines (21 loc) · 1.2 KB
/
build.workaround-missing-resource.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Source - https://github.com/nenick/AndroidStudioAndRobolectric/blob/master/app/build.workaround-missing-resource.gradle
// Workaround for missing test resources when running unit tests within android studio.
// This copies the test resources next to the test classes for each variant.
// Tracked at https://github.com/nenick/AndroidStudioAndRobolectric/issues/7
// Original solution comes from https://code.google.com/p/android/issues/detail?id=136013#c10
// See also https://code.google.com/p/android/issues/detail?id=64887
gradle.projectsEvaluated {
// Base path which is recognized by android studio.
def testClassesPath = "${buildDir}/intermediates/"
// Copy must be done for each variant.
def variants = android.libraryVariants.collect()
variants.each { variant ->
def variationName = variant.name.capitalize()
def variationPath = variant.buildType.name
// Specific copy task for each variant
def copyTestResourcesTask = project.tasks.create("copyTest${variationName}Resources", Copy)
copyTestResourcesTask.from("${projectDir}/src/test/resources")
copyTestResourcesTask.into("${testClassesPath}/sourceFolderJavaResources/${variationPath}")
copyTestResourcesTask.execute()
}
}