Unlink instrumentation tests from the check task.
A clear separation between checks that requires and those that do
not require a device is better. This will allow to run lint and
other non-device checks separately more easily.
Also fix an issue with the location of ZipAlign.
Change-Id: I4fd58d6313ed5ab4559da0b3954b555ff1f41bcd
diff --git a/builder/src/main/java/com/android/builder/DefaultSdkParser.java b/builder/src/main/java/com/android/builder/DefaultSdkParser.java
index 8fb0830..91dfa36 100644
--- a/builder/src/main/java/com/android/builder/DefaultSdkParser.java
+++ b/builder/src/main/java/com/android/builder/DefaultSdkParser.java
@@ -50,6 +50,7 @@
private final String mSdkLocation;
private SdkManager mManager;
+ private File mTools;
private File mPlatformTools;
private final Map<String, File> mToolsMap = Maps.newHashMapWithExpectedSize(6);
@@ -82,7 +83,7 @@
@Override
public FullRevision getPlatformToolsRevision() {
- File platformTools = getPlatformTools();
+ File platformTools = getPlatformToolsFolder();
if (!platformTools.isDirectory()) {
return null;
}
@@ -114,22 +115,22 @@
@Override
public File getAapt() {
- return getTool(SdkConstants.FN_AAPT);
+ return getPlatformTool(SdkConstants.FN_AAPT);
}
@Override
public File getAidlCompiler() {
- return getTool(SdkConstants.FN_AIDL);
+ return getPlatformTool(SdkConstants.FN_AIDL);
}
@Override
public File getRenderscriptCompiler() {
- return getTool(SdkConstants.FN_RENDERSCRIPT);
+ return getPlatformTool(SdkConstants.FN_RENDERSCRIPT);
}
@Override
public File getDx() {
- return getTool(SdkConstants.FN_DX);
+ return getPlatformTool(SdkConstants.FN_DX);
}
@Override
@@ -139,13 +140,13 @@
@Override
public File getAdb() {
- return getTool(SdkConstants.FN_ADB);
+ return getPlatformTool(SdkConstants.FN_ADB);
}
- private File getTool(String filename) {
+ private File getPlatformTool(String filename) {
File f = mToolsMap.get(filename);
if (f == null) {
- File platformTools = getPlatformTools();
+ File platformTools = getPlatformToolsFolder();
if (!platformTools.isDirectory()) {
return null;
}
@@ -157,11 +158,35 @@
return f;
}
- private File getPlatformTools() {
+ private File getTool(String filename) {
+ File f = mToolsMap.get(filename);
+ if (f == null) {
+ File platformTools = getToolsFolder();
+ if (!platformTools.isDirectory()) {
+ return null;
+ }
+
+ f = new File(platformTools, filename);
+ mToolsMap.put(filename, f);
+ }
+
+ return f;
+ }
+
+ private File getPlatformToolsFolder() {
if (mPlatformTools == null) {
mPlatformTools = new File(mSdkLocation, FD_PLATFORM_TOOLS);
}
return mPlatformTools;
}
+
+ private File getToolsFolder() {
+ if (mTools == null) {
+ mTools = new File(mSdkLocation, FD_TOOLS);
+ }
+
+ return mTools;
+ }
+
}
diff --git a/changelog.txt b/changelog.txt
index 655af00..14ede6d 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -12,14 +12,15 @@
- API to manipulate Build Variants.
- Support for versionName suffix provided by the BuildType.
- Testing
- * Tests now runs on all connected devices in parallel.
- * Running tests on device now breaks the build if any test fails.
- * Generate an HTML report for each flavor/project, but also aggregated.
+ * Instrumentation tests now started from "deviceCheck" instead of "check"
+ * Instrumentation tests now run on all connected devices in parallel.
+ * Instrumentation tests now break the build if any test fails.
+ * Instrumentation tests now generate an HTML report for each flavor/project, but also aggregated.
* New plugin 'android-reporting' to aggregate android test results across projects. See 'flavorlib' sample.
- Improved DSL:
- * replaced android.target with android.compileSdkVersion to make it less confusing vs min/targetSdkVersion
+ * replaced android.target with android.compileSdkVersion to make it less confusing with targetSdkVersion
* signing information now a SigningConfig object reusable across BuildType and ProductFlavor
- * ability to relocated a full sourceSet. See 'migrated' sample.
+ * ability to relocate a full sourceSet. See 'migrated' sample.
* Fixes:
- Default Java compile target set to 1.6.
- Fix generation of R classes in case libraries share same package name as the app project.
diff --git a/gradle/src/device-test/groovy/com/android/build/gradle/DeviceTest.java b/gradle/src/device-test/groovy/com/android/build/gradle/DeviceTest.java
index 066859c..bb78d2e 100644
--- a/gradle/src/device-test/groovy/com/android/build/gradle/DeviceTest.java
+++ b/gradle/src/device-test/groovy/com/android/build/gradle/DeviceTest.java
@@ -68,7 +68,7 @@
@Override
protected void runTest() throws Throwable {
try {
- runTasksOnProject(projectName, gradleVersion, "check");
+ runTasksOnProject(projectName, gradleVersion, "deviceCheck");
} finally {
// because runTasksOnProject will throw an exception if the gradle side fails, do this
// in the finally block.
diff --git a/gradle/src/main/groovy/com/android/build/gradle/AppPlugin.groovy b/gradle/src/main/groovy/com/android/build/gradle/AppPlugin.groovy
index 15f36f5..7e70b0e 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/AppPlugin.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/AppPlugin.groovy
@@ -120,6 +120,11 @@
}
+ /**
+ * Adds new BuildType, creating a BuildTypeData, and the associated source set,
+ * and adding it to the map.
+ * @param buildType the build type.
+ */
private void addBuildType(BuildType buildType) {
String name = buildType.name
if (name.startsWith("test")) {
@@ -137,6 +142,12 @@
buildTypes[name] = buildTypeData
}
+ /**
+ * Adds a new ProductFlavor, creating a ProductFlavorData and associated source sets,
+ * and adding it to the map.
+ *
+ * @param productFlavor the product flavor
+ */
private void addProductFlavor(GroupableProductFlavor productFlavor) {
if (productFlavor.name.startsWith("test")) {
throw new RuntimeException("ProductFlavor names cannot start with 'test'")
@@ -156,6 +167,9 @@
productFlavors[productFlavor.name] = productFlavorData
}
+ /**
+ * Task creation entry point.
+ */
@Override
protected void doCreateAndroidTasks() {
// resolve dependencies for all config
@@ -174,11 +188,11 @@
assembleTest.description = "Assembles all the Test applications"
// same for the test task
- testTask = project.tasks.add("test", AndroidReportTask)
+ testTask = project.tasks.add("instrumentationTest", AndroidReportTask)
testTask.group = JavaBasePlugin.VERIFICATION_GROUP
- testTask.description = "Installs and runs tests for all flavors"
+ testTask.description = "Installs and runs instrumentation tests for all flavors"
testTask.reportType = ReportType.MULTI_FLAVOR
- project.tasks.check.dependsOn testTask
+ deviceCheck.dependsOn testTask
testTask.conventionMapping.resultsDir = {
String rootLocation = extension.testOptions.resultsDir != null ?
@@ -238,19 +252,36 @@
}
}
+ /**
+ * Creates the tasks for multi-flavor builds.
+ *
+ * This recursively fills the array of ProductFlavorData (in the order defined
+ * in extension.flavorGroupList), creating all possible combination.
+ *
+ * @param datas the arrays to fill
+ * @param i the current index to fill
+ * @param map the map of group -> list(ProductFlavor)
+ * @return
+ */
private createTasksForMultiFlavoredBuilds(ProductFlavorData[] datas, int i,
- ListMultimap<String, ProductFlavorData> map) {
+ ListMultimap<String, ? extends ProductFlavorData> map) {
if (i == datas.length) {
createTasksForFlavoredBuild(datas)
return
}
- // fill the array at the current index
+ // fill the array at the current index.
+ // get the group name that matches the index we are filling.
def group = extension.flavorGroupList.get(i)
+
+ // from our map, get all the possible flavors in that group.
def flavorList = map.get(group)
+
+ // loop on all the flavors to add them to the current index and recursively fill the next
+ // indices.
for (ProductFlavorData flavor : flavorList) {
datas[i] = flavor
- createTasksForMultiFlavoredBuilds(datas, i+1, map)
+ createTasksForMultiFlavoredBuilds(datas, (int) i + 1, map)
}
}
diff --git a/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy b/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy
index 8e7563b..968e655 100644
--- a/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy
+++ b/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy
@@ -113,6 +113,7 @@
protected Task uninstallAll
protected Task assembleTest
+ protected Task deviceCheck
protected abstract String getTarget()
@@ -137,6 +138,10 @@
uninstallAll.description = "Uninstall all applications."
uninstallAll.group = INSTALL_GROUP
+ deviceCheck = project.tasks.add("deviceCheck")
+ deviceCheck.description = "Runs all checks that requires a connected device."
+ deviceCheck.group = JavaBasePlugin.VERIFICATION_GROUP
+
project.afterEvaluate {
createAndroidTasks()
}
@@ -672,14 +677,15 @@
}
// create the check task for this test
- def testFlavorTask = project.tasks.add(mainTestTask ? "test" : "test${testedVariant.name}",
+ def testFlavorTask = project.tasks.add(
+ mainTestTask ? "instrumentationTest" : "instrumentationTest${testedVariant.name}",
mainTestTask ? TestLibraryTask : TestFlavorTask)
testFlavorTask.description = "Installs and runs the tests for Build ${testedVariant.name}."
testFlavorTask.group = JavaBasePlugin.VERIFICATION_GROUP
testFlavorTask.dependsOn testedVariant.assembleTask, variant.assembleTask
if (mainTestTask) {
- project.tasks.check.dependsOn testFlavorTask
+ deviceCheck.dependsOn testFlavorTask
}
testFlavorTask.plugin = this