Skip to content

Commit

Permalink
Change MIN_BUILD_TOOLS_REVISION to 30.0.0
Browse files Browse the repository at this point in the history
Bazel's Android tools requires Android Build Tools 30.0.0 or newer.

See bazelbuild#13409

RELNOTES: The minimum Android build tools version for the Android rules is now 30.0.0
PiperOrigin-RevId: 378014192
  • Loading branch information
ahumesky authored and copybara-github committed Jun 7, 2021
1 parent c88b57a commit 0e65273
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 18 deletions.
2 changes: 1 addition & 1 deletion site/docs/tutorial/android-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> PATH_ENV_VAR_AS_LIST = ImmutableList.of(PATH_ENV_VAR);
private static final ImmutableList<String> LOCAL_MAVEN_REPOSITORIES =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
<p>Bazel requires build tools version 26.0.1 or later.
<p>Bazel requires build tools version 30.0.0 or later.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(attr("build_tools_version", STRING).nonconfigurable("WORKSPACE rule"))
/* <!-- #BLAZE_RULE(android_sdk_repository).ATTRIBUTE(api_level) -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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");
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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(
Expand All @@ -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"),
Expand All @@ -243,21 +273,20 @@ 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"),
"local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')",
"android_sdk_repository(",
" name = 'androidsdk',",
" path = '/sdk',",
" build_tools_version = '26.0.1',",
")");
invalidatePackages();

Expand All @@ -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"),
Expand All @@ -280,7 +309,6 @@ public void testMultipleAndroidSdkApiLevels() throws Exception {
" name = 'androidsdk',",
" path = '/sdk',",
" api_level = 24,",
" build_tools_version = '26.0.1',",
")");
invalidatePackages();

Expand All @@ -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"),
Expand All @@ -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);
Expand All @@ -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(
Expand All @@ -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"),
Expand Down

0 comments on commit 0e65273

Please sign in to comment.