From 59d3153ee13df75169b402083cc9bcf99778e04b 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 00de0c1691a64f..ff0d41aec16acd 100644 --- a/site/docs/tutorial/android-app.md +++ b/site/docs/tutorial/android-app.md @@ -155,7 +155,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 a3b67c2bd699e0..d2c3829e6007e8 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 @@ -158,7 +158,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 390c7cd2f01e33..dccf8dcd5f05aa 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 @@ -58,6 +58,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); } @@ -85,7 +90,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( @@ -107,7 +112,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( @@ -127,7 +132,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"); @@ -158,7 +163,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"), @@ -193,7 +198,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( @@ -207,10 +212,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"), @@ -225,13 +255,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"), @@ -239,7 +269,6 @@ public void testApiLevelHighestVersionDetection() throws Exception { "android_sdk_repository(", " name = 'androidsdk',", " path = '/sdk',", - " build_tools_version = '26.0.1',", ")"); invalidatePackages(); @@ -253,7 +282,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"), @@ -262,7 +291,6 @@ public void testMultipleAndroidSdkApiLevels() throws Exception { " name = 'androidsdk',", " path = '/sdk',", " api_level = 24,", - " build_tools_version = '26.0.1',", ")"); invalidatePackages(); @@ -278,7 +306,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"), @@ -287,7 +315,6 @@ public void testMissingApiLevel() throws Exception { " name = 'androidsdk',", " path = '/sdk',", " api_level = 25,", - " build_tools_version = '26.0.1',", ")"); invalidatePackages(); reporter.removeHandler(failFastHandler); @@ -308,7 +335,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( @@ -325,7 +352,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"),