Skip to content

Commit cd20367

Browse files
committed
fix: update android build paths
1 parent f20049b commit cd20367

File tree

1 file changed

+27
-38
lines changed

1 file changed

+27
-38
lines changed

scripts/build.py

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -254,22 +254,24 @@ def run_gradle_command(self, working_dir, command):
254254
return False
255255

256256
def build_android_target(self, target):
257-
"""build a specific Android target JAR"""
257+
"""build a specific Android target JAR using React Native approach"""
258258
self._print_brewing("Building", f"Android {target}")
259259

260-
test_project_path = self.sdk_path / "tests" / target
260+
# Build from SDK root directory (like React Native script)
261+
build_mode = "debug"
262+
build_mode_cap = build_mode.capitalize()
261263

262264
if target == "test-library":
263-
# use assembleDebug and get JAR from AAR structure (like Cordova script)
265+
# use proper Gradle task with project namespace
264266
success = self.run_gradle_command(
265-
test_project_path,
266-
["clean", "assembleDebug"]
267+
self.sdk_path,
268+
["clean", f":tests:test-library:assemble{build_mode_cap}"]
267269
)
268270
if not success:
269271
return False
270272

271-
# check if the JAR was created in AAR structure
272-
jar_path = test_project_path / "build" / "intermediates" / "aar_main_jar" / "debug" / "syncDebugLibJars" / "classes.jar"
273+
# check if the JAR was created using React Native path structure
274+
jar_path = self.sdk_path / "tests" / "test-library" / "build" / "intermediates" / "aar_main_jar" / build_mode / f"sync{build_mode_cap}LibJars" / "classes.jar"
273275
if not jar_path.exists():
274276
self._print_error(f"JAR not found at expected location: {jar_path}")
275277
return False
@@ -278,29 +280,22 @@ def build_android_target(self, target):
278280
return jar_path, "adjust-test-library.jar"
279281

280282
elif target == "test-options":
281-
# build the test-options project
283+
# use proper Gradle task with project namespace
282284
success = self.run_gradle_command(
283-
test_project_path,
284-
["clean", "assembleDebug"]
285+
self.sdk_path,
286+
["clean", f":tests:test-options:assemble{build_mode_cap}"]
285287
)
286288
if not success:
287289
return False
288290

289-
# create the libs directory if it doesn't exist
290-
libs_dir = test_project_path / "build" / "libs"
291-
libs_dir.mkdir(parents=True, exist_ok=True)
292-
293-
# copy the compiled classes JAR to a proper location
294-
source_jar = test_project_path / "build" / "intermediates" / "aar_main_jar" / "debug" / "syncDebugLibJars" / "classes.jar"
295-
target_jar = libs_dir / "test-options-debug.jar"
296-
297-
if not source_jar.exists():
298-
self._print_error(f"Source JAR not found at: {source_jar}")
291+
# check if the JAR was created using React Native path structure
292+
jar_path = self.sdk_path / "tests" / "test-options" / "build" / "intermediates" / "aar_main_jar" / build_mode / f"sync{build_mode_cap}LibJars" / "classes.jar"
293+
if not jar_path.exists():
294+
self._print_error(f"JAR not found at expected location: {jar_path}")
299295
return False
300296

301-
shutil.copy2(source_jar, target_jar)
302-
self._print_success(f"JAR created at: {target_jar}")
303-
return target_jar, "adjust-test-options.jar"
297+
self._print_success(f"JAR created at: {jar_path}")
298+
return jar_path, "adjust-test-options.jar"
304299

305300
return False
306301

@@ -387,8 +382,7 @@ def build(self):
387382
self._print_error("Prerequisites check failed")
388383
return False
389384

390-
# build all targets for the platform
391-
built_artifacts = []
385+
# build and copy each target immediately
392386
for target in self.test_targets:
393387
if self.platform == "android":
394388
result = self.build_android_target(target)
@@ -402,20 +396,15 @@ def build(self):
402396
self._print_error(f"Failed to build {self.platform} {target}")
403397
return False
404398

405-
built_artifacts.append(result)
406-
407-
# copy all built artifacts
408-
if self.platform == "android":
409-
self._print_brewing("Copying", "JAR files")
410-
for source_jar_path, target_name in built_artifacts:
411-
if not self.copy_jar(source_jar_path, target_name):
412-
self._print_error("Failed to copy JAR files")
399+
# copy the artifact immediately after building
400+
source_path, target_name = result
401+
if self.platform == "android":
402+
if not self.copy_jar(source_path, target_name):
403+
self._print_error(f"Failed to copy {target}")
413404
return False
414-
elif self.platform == "ios":
415-
self._print_brewing("Copying", "framework files")
416-
for source_framework_path, target_name in built_artifacts:
417-
if not self.copy_framework(source_framework_path, target_name):
418-
self._print_error("Failed to copy framework files")
405+
elif self.platform == "ios":
406+
if not self.copy_framework(source_path, target_name):
407+
self._print_error(f"Failed to copy {target}")
419408
return False
420409

421410
print(f"{Colors.GREEN}{Colors.BOLD}🎉 All {self.target} components built and copied successfully!{Colors.END}")

0 commit comments

Comments
 (0)