aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2020-11-04 15:22:52 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2020-11-04 15:22:52 +0000
commit4f3dd083ac399c045e774282cfe1f48e6e16f239 (patch)
treea5cbbb3740731d5f16d86059ab5f172fc9873fbe
parente647036b895a4765859d926f5f072bbc5cf0a2eb (diff)
parent216d5e7252168fef3d27f790b9e3bb33f6dc4c8a (diff)
downloadplatform_tools_base-studio-master-dev.tar.gz
platform_tools_base-studio-master-dev.tar.bz2
platform_tools_base-studio-master-dev.zip
Merge cherrypicks of [12986203, 12985811] into studio-4.1-releasestudio-4.1.1studio-master-dev
Change-Id: If35f32983cf3f28f747a15248e962e61d043bbf9
-rw-r--r--build-system/gradle-core/src/main/java/com/android/build/api/component/impl/ComponentImpl.kt2
-rw-r--r--build-system/gradle-core/src/main/java/com/android/build/api/component/impl/ComponentPropertiesImpl.kt6
-rw-r--r--build-system/gradle-core/src/main/java/com/android/build/gradle/internal/TaskManager.java3
-rw-r--r--build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/factory/AndroidUnitTest.java3
-rw-r--r--build-system/integration-test/application/src/test/java/com/android/build/gradle/integration/resources/DisableLibraryResourcesTest.kt34
5 files changed, 43 insertions, 5 deletions
diff --git a/build-system/gradle-core/src/main/java/com/android/build/api/component/impl/ComponentImpl.kt b/build-system/gradle-core/src/main/java/com/android/build/api/component/impl/ComponentImpl.kt
index d6460e2ed3..492ee88d26 100644
--- a/build-system/gradle-core/src/main/java/com/android/build/api/component/impl/ComponentImpl.kt
+++ b/build-system/gradle-core/src/main/java/com/android/build/api/component/impl/ComponentImpl.kt
@@ -46,4 +46,4 @@ abstract class ComponentImpl<PropertiesT : ComponentPropertiesImpl>(
fun executePropertiesActions(target: PropertiesT) {
propertiesActions.executeActions(target)
}
-} \ No newline at end of file
+}
diff --git a/build-system/gradle-core/src/main/java/com/android/build/api/component/impl/ComponentPropertiesImpl.kt b/build-system/gradle-core/src/main/java/com/android/build/api/component/impl/ComponentPropertiesImpl.kt
index 391654bba6..e881f42c1b 100644
--- a/build-system/gradle-core/src/main/java/com/android/build/api/component/impl/ComponentPropertiesImpl.kt
+++ b/build-system/gradle-core/src/main/java/com/android/build/api/component/impl/ComponentPropertiesImpl.kt
@@ -502,7 +502,11 @@ abstract class ComponentPropertiesImpl(
artifacts.get(COMPILE_AND_RUNTIME_NOT_NAMESPACED_R_CLASS_JAR)
)
} else {
- internalServices.fileCollection(variantScope.rJarForUnitTests)
+ if (buildFeatures.androidResources) {
+ internalServices.fileCollection(variantScope.rJarForUnitTests)
+ } else {
+ internalServices.fileCollection()
+ }
}
}
}
diff --git a/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/TaskManager.java b/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/TaskManager.java
index e01ebe3728..8c678e89ee 100644
--- a/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/TaskManager.java
+++ b/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/TaskManager.java
@@ -1733,7 +1733,8 @@ public abstract class TaskManager<
testConfigInputs.getPackageNameOfFinalRClass());
});
} else {
- if (testedVariant.getVariantType().isAar()) {
+ if (testedVariant.getVariantType().isAar()
+ && testedVariant.getBuildFeatures().getAndroidResources()) {
// With compile classpath R classes, we need to generate a dummy R class for unit tests
// See https://issuetracker.google.com/143762955 for more context.
taskFactory.register(
diff --git a/build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/factory/AndroidUnitTest.java b/build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/factory/AndroidUnitTest.java
index 36f53b72c1..44978ff112 100644
--- a/build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/factory/AndroidUnitTest.java
+++ b/build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/factory/AndroidUnitTest.java
@@ -195,7 +195,8 @@ public abstract class AndroidUnitTest extends Test implements VariantAwareTask {
RUNTIME_CLASSPATH, ALL, ArtifactType.JAVA_RES));
// 4. The separately compile R class, if applicable.
- if (!globalScope.getExtension().getAaptOptions().getNamespaced()) {
+ if (creationConfig.getBuildFeatures().getAndroidResources()
+ && !globalScope.getExtension().getAaptOptions().getNamespaced()) {
collection.from(component.getVariantScope().getRJarForUnitTests());
}
diff --git a/build-system/integration-test/application/src/test/java/com/android/build/gradle/integration/resources/DisableLibraryResourcesTest.kt b/build-system/integration-test/application/src/test/java/com/android/build/gradle/integration/resources/DisableLibraryResourcesTest.kt
index 4e27a72517..f1e54cf9f7 100644
--- a/build-system/integration-test/application/src/test/java/com/android/build/gradle/integration/resources/DisableLibraryResourcesTest.kt
+++ b/build-system/integration-test/application/src/test/java/com/android/build/gradle/integration/resources/DisableLibraryResourcesTest.kt
@@ -23,6 +23,7 @@ import com.android.build.gradle.integration.common.truth.ScannerSubject
import com.android.build.gradle.integration.common.truth.TruthHelper
import com.android.build.gradle.integration.common.utils.TestFileUtils
import com.android.build.gradle.options.BooleanOption
+import com.android.testutils.truth.PathSubject
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
@@ -45,6 +46,27 @@ class DisableLibraryResourcesTest {
</resources>""".trimIndent()
)
.withFile("src/main/res/raw/raw_file", "leafLib")
+ .withFile("src/test/java/com/example/MyTest.java",
+ //language=java
+ """
+ package com.example;
+
+ import org.junit.Test;
+
+ public class MyTest {
+ @Test
+ public void check() {
+ System.out.println("ExampleTest has some output");
+ }
+ }
+ """.trimIndent())
+ .appendToBuild("""
+
+ dependencies {
+ testImplementation("junit:junit:4.12")
+ }
+
+ """.trimIndent())
private val localLib = MinimalSubProject.lib("com.example.localLib")
.withFile(
@@ -195,4 +217,14 @@ class DisableLibraryResourcesTest {
assertThat(result.didWorkTasks).contains(":localLib:parseDebugLocalResources")
assertThat(result.didWorkTasks).contains(":leafLib:parseDebugLocalResources")
}
-} \ No newline at end of file
+
+ @Test
+ fun testAndroidAndUnitTests() {
+ project.executor().with(BooleanOption.BUILD_FEATURE_ANDROID_RESOURCES, false)
+ .run(":leaflib:assembleDebugAndroidTest", ":leaflib:test")
+ assertThat(project.file("leafLib/build/reports/tests/testReleaseUnitTest/classes/com.example.MyTest.html").readText())
+ .contains("ExampleTest has some output")
+ assertThat(project.file("leafLib/build/reports/tests/testDebugUnitTest/classes/com.example.MyTest.html").readText())
+ .contains("ExampleTest has some output")
+ }
+}