From 0e652737988e3c115e98e1552f6fada52bc2b9a2 Mon Sep 17 00:00:00 2001 From: ahumesky Date: Mon, 7 Jun 2021 15:04:11 -0700 Subject: [PATCH] Change MIN_BUILD_TOOLS_REVISION to 30.0.0 Bazel's Android tools requires Android Build Tools 30.0.0 or newer. See https://github.com/bazelbuild/bazel/issues/13409 RELNOTES: The minimum Android build tools version for the Android rules is now 30.0.0 PiperOrigin-RevId: 378014192 --- site/docs/tutorial/android-app.md | 2 +- .../android/AndroidSdkRepositoryFunction.java | 2 +- .../android/AndroidSdkRepositoryRule.java | 2 +- .../android/AndroidSdkRepositoryTest.java | 57 ++++++++++++++----- 4 files changed, 45 insertions(+), 18 deletions(-) diff --git a/site/docs/tutorial/android-app.md b/site/docs/tutorial/android-app.md index 36be5b4c75bf47..dbfc7c73446537 100644 --- a/site/docs/tutorial/android-app.md +++ b/site/docs/tutorial/android-app.md @@ -176,7 +176,7 @@ android_sdk_repository( name = "androidsdk", path = "/path/to/Android/sdk", api_level = 25, - build_tools_version = "26.0.1" + build_tools_version = "30.0.3" ) ``` diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java index 2938a55090a636..3d3df257b718b5 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java @@ -159,7 +159,7 @@ public String toString() { private static final PathFragment BUILD_TOOLS_DIR = PathFragment.create("build-tools"); private static final PathFragment PLATFORMS_DIR = PathFragment.create("platforms"); private static final PathFragment SYSTEM_IMAGES_DIR = PathFragment.create("system-images"); - private static final AndroidRevision MIN_BUILD_TOOLS_REVISION = AndroidRevision.parse("26.0.1"); + private static final AndroidRevision MIN_BUILD_TOOLS_REVISION = AndroidRevision.parse("30.0.0"); private static final String PATH_ENV_VAR = "ANDROID_HOME"; private static final ImmutableList PATH_ENV_VAR_AS_LIST = ImmutableList.of(PATH_ENV_VAR); private static final ImmutableList LOCAL_MAVEN_REPOSITORIES = diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryRule.java index b8ec9bf3dfdbb0..c947c92a7943f1 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryRule.java @@ -72,7 +72,7 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment envi The version of the Android build tools to use from within the Android SDK. If not specified, the latest build tools version installed will be used. -

Bazel requires build tools version 26.0.1 or later. +

Bazel requires build tools version 30.0.0 or later. */ .add(attr("build_tools_version", STRING).nonconfigurable("WORKSPACE rule")) /* diff --git a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryTest.java b/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryTest.java index b66547b3bf8c30..65c7ce3a325fcd 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryTest.java @@ -76,6 +76,11 @@ private void scratchSystemImagesDirectories(String... pathFragments) throws Exce } private void scratchBuildToolsDirectories(String... versions) throws Exception { + if (versions.length == 0) { + // Use a large version number here so that we don't have to update this test as + // AndroidSdkRepositoryFunction.MIN_BUILD_TOOLS_REVISION increases. + versions = new String[] {"400.0.0"}; + } for (String version : versions) { scratch.dir("/sdk/build-tools/" + version); } @@ -103,7 +108,7 @@ private void scratchExtrasLibrary( @Test public void testGeneratedAarImport() throws Exception { scratchPlatformsDirectories(25); - scratchBuildToolsDirectories("26.0.1"); + scratchBuildToolsDirectories(); scratchExtrasLibrary("extras/google/m2repository", "com.google.android", "foo", "1.0.0", "aar"); String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString(); FileSystemUtils.appendIsoLatin1( @@ -125,7 +130,7 @@ public void testGeneratedAarImport() throws Exception { @Test public void testExportsExtrasLibraryArtifacts() throws Exception { scratchPlatformsDirectories(25); - scratchBuildToolsDirectories("26.0.1"); + scratchBuildToolsDirectories(); scratchExtrasLibrary("extras/google/m2repository", "com.google.android", "foo", "1.0.0", "aar"); String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString(); FileSystemUtils.appendIsoLatin1( @@ -145,7 +150,7 @@ public void testExportsExtrasLibraryArtifacts() throws Exception { @Test public void testKnownSdkMavenRepositories() throws Exception { scratchPlatformsDirectories(25); - scratchBuildToolsDirectories("26.0.1"); + scratchBuildToolsDirectories(); scratchExtrasLibrary("extras/google/m2repository", "com.google.android", "a", "1.0.0", "jar"); scratchExtrasLibrary("extras/android/m2repository", "com.android.support", "b", "1.0.0", "aar"); scratchExtrasLibrary("extras/m2repository", "com.android.support", "c", "1.0.1", "aar"); @@ -176,7 +181,7 @@ public void testKnownSdkMavenRepositories() throws Exception { @Test public void testSystemImageDirectoriesAreFound() throws Exception { scratchPlatformsDirectories(25); - scratchBuildToolsDirectories("26.0.1"); + scratchBuildToolsDirectories(); String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString(); FileSystemUtils.appendIsoLatin1( scratch.resolve("WORKSPACE"), @@ -211,7 +216,7 @@ public void testSystemImageDirectoriesAreFound() throws Exception { @Test public void testMalformedSystemImageDirectories() throws Exception { scratchPlatformsDirectories(25, 26); - scratchBuildToolsDirectories("26.0.1"); + scratchBuildToolsDirectories(); scratchSystemImagesDirectories("android-25/default/armeabi-v7a", "android-O/google_apis/x86"); String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString(); FileSystemUtils.appendIsoLatin1( @@ -225,10 +230,35 @@ public void testMalformedSystemImageDirectories() throws Exception { assertThat(getConfiguredTarget("@androidsdk//:emulator_images_android_25_arm")).isNotNull(); } + @Test + public void testBuildToolsVersion() throws Exception { + scratchPlatformsDirectories(25); + // Use large version numbers here so that we don't have to update this test as + // AndroidSdkRepositoryFunction.MIN_BUILD_TOOLS_REVISION increases. + scratchBuildToolsDirectories("400.0.1", "400.0.2", "400.0.3"); + String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString(); + FileSystemUtils.appendIsoLatin1( + scratch.resolve("WORKSPACE"), + "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')", + "android_sdk_repository(", + " name = 'androidsdk',", + " path = '/sdk',", + " build_tools_version = '400.0.2',", + ")"); + invalidatePackages(); + + ConfiguredTarget androidSdk = getConfiguredTarget("@androidsdk//:sdk"); + assertThat(androidSdk).isNotNull(); + assertThat(androidSdk.get(AndroidSdkProvider.PROVIDER).getBuildToolsVersion()) + .isEqualTo("400.0.2"); + } + @Test public void testBuildToolsHighestVersionDetection() throws Exception { scratchPlatformsDirectories(25); - scratchBuildToolsDirectories("26.0.1", "26.0.2"); + // Use large version numbers here so that we don't have to update this test as + // AndroidSdkRepositoryFunction.MIN_BUILD_TOOLS_REVISION increases. + scratchBuildToolsDirectories("400.0.1", "400.0.2"); String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString(); FileSystemUtils.appendIsoLatin1( scratch.resolve("WORKSPACE"), @@ -243,13 +273,13 @@ public void testBuildToolsHighestVersionDetection() throws Exception { ConfiguredTarget androidSdk = getConfiguredTarget("@androidsdk//:sdk"); assertThat(androidSdk).isNotNull(); assertThat(androidSdk.get(AndroidSdkProvider.PROVIDER).getBuildToolsVersion()) - .isEqualTo("26.0.2"); + .isEqualTo("400.0.2"); } @Test public void testApiLevelHighestVersionDetection() throws Exception { scratchPlatformsDirectories(24, 25, 23); - scratchBuildToolsDirectories("26.0.1"); + scratchBuildToolsDirectories(); String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString(); FileSystemUtils.appendIsoLatin1( scratch.resolve("WORKSPACE"), @@ -257,7 +287,6 @@ public void testApiLevelHighestVersionDetection() throws Exception { "android_sdk_repository(", " name = 'androidsdk',", " path = '/sdk',", - " build_tools_version = '26.0.1',", ")"); invalidatePackages(); @@ -271,7 +300,7 @@ public void testApiLevelHighestVersionDetection() throws Exception { public void testMultipleAndroidSdkApiLevels() throws Exception { int[] apiLevels = {23, 24, 25}; scratchPlatformsDirectories(apiLevels); - scratchBuildToolsDirectories("26.0.1"); + scratchBuildToolsDirectories(); String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString(); FileSystemUtils.appendIsoLatin1( scratch.resolve("WORKSPACE"), @@ -280,7 +309,6 @@ public void testMultipleAndroidSdkApiLevels() throws Exception { " name = 'androidsdk',", " path = '/sdk',", " api_level = 24,", - " build_tools_version = '26.0.1',", ")"); invalidatePackages(); @@ -296,7 +324,7 @@ public void testMultipleAndroidSdkApiLevels() throws Exception { @Test public void testMissingApiLevel() throws Exception { scratchPlatformsDirectories(24); - scratchBuildToolsDirectories("26.0.1"); + scratchBuildToolsDirectories(); String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString(); FileSystemUtils.appendIsoLatin1( scratch.resolve("WORKSPACE"), @@ -305,7 +333,6 @@ public void testMissingApiLevel() throws Exception { " name = 'androidsdk',", " path = '/sdk',", " api_level = 25,", - " build_tools_version = '26.0.1',", ")"); invalidatePackages(); reporter.removeHandler(failFastHandler); @@ -326,7 +353,7 @@ public void testMissingApiLevel() throws Exception { @Test public void testFilesInSystemImagesDirectories() throws Exception { scratchPlatformsDirectories(24); - scratchBuildToolsDirectories("26.0.1"); + scratchBuildToolsDirectories(); scratch.file("/sdk/system-images/.DS_Store"); String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString(); FileSystemUtils.appendIsoLatin1( @@ -343,7 +370,7 @@ public void testFilesInSystemImagesDirectories() throws Exception { @Test public void testMissingPlatformsDirectory() throws Exception { - scratchBuildToolsDirectories("26.0.1"); + scratchBuildToolsDirectories(); String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString(); FileSystemUtils.appendIsoLatin1( scratch.resolve("WORKSPACE"),