Skip to content

Commit f196fb6

Browse files
committed
Ensure compileSdkVersion is set for Android UI tests
1 parent 93a4996 commit f196fb6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

scripts/update_android_ui_test_gradle.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import re
88
import sys
99

10+
COMPILE_SDK_LINE = " compileSdkVersion 33\n"
11+
1012
TEST_OPTIONS_SNIPPET = """ testOptions {\n animationsDisabled = true\n }\n\n"""
1113

1214
DEFAULT_CONFIG_SNIPPET = """ defaultConfig {\n testInstrumentationRunner \"androidx.test.runner.AndroidJUnitRunner\"\n }\n\n"""
@@ -46,6 +48,17 @@ def find_block(self, name: str, start: int = 0) -> tuple[int, int] | None:
4648
index += 1
4749
return None
4850

51+
def ensure_compile_sdk(self) -> None:
52+
if re.search(r"compileSdkVersion\s+\d+", self.content):
53+
return
54+
android_block = self.find_block("android")
55+
if not android_block:
56+
raise SystemExit("Unable to locate android block in Gradle file")
57+
insert = self.content.find('\n', android_block[0]) + 1
58+
if insert <= 0:
59+
insert = android_block[0] + len("android {")
60+
self.content = self.content[:insert] + COMPILE_SDK_LINE + self.content[insert:]
61+
4962
def ensure_test_options(self) -> None:
5063
if "animationsDisabled" in self.content:
5164
return
@@ -155,6 +168,7 @@ def _select_configuration(block: str, content: str) -> str:
155168
return "androidTestImplementation"
156169

157170
def apply(self) -> None:
171+
self.ensure_compile_sdk()
158172
self.ensure_test_options()
159173
self.ensure_instrumentation_runner()
160174
self.ensure_dependencies()

0 commit comments

Comments
 (0)