From 1f257c4a8559e7b0cdbd6565f24ea97d0abd12fe Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 25 Feb 2025 15:06:02 -0500 Subject: [PATCH] pure_android_host_apps/android_host_app_v2_embedding multiple gradle and AGP versions (#163849) Fixes #163750 Adds local.properties in any directory to the repo wide gitignore. Test changes to make the test easier to debug, specifically identifying the difference between a debug and release failure. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --- ...uild_android_host_app_with_module_aar.dart | 37 +++++++++++++++---- .../build.gradle | 2 +- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/dev/devicelab/bin/tasks/build_android_host_app_with_module_aar.dart b/dev/devicelab/bin/tasks/build_android_host_app_with_module_aar.dart index 80a5b32276..0668e7d59c 100644 --- a/dev/devicelab/bin/tasks/build_android_host_app_with_module_aar.dart +++ b/dev/devicelab/bin/tasks/build_android_host_app_with_module_aar.dart @@ -12,6 +12,7 @@ import 'package:flutter_devicelab/framework/framework.dart'; import 'package:flutter_devicelab/framework/task_result.dart'; import 'package:flutter_devicelab/framework/utils.dart'; import 'package:path/path.dart' as path; +import 'package:pub_semver/pub_semver.dart'; final String gradlew = Platform.isWindows ? 'gradlew.bat' : 'gradlew'; final String gradlewExecutable = Platform.isWindows ? '.\\$gradlew' : './$gradlew'; @@ -33,10 +34,14 @@ TaskFunction combine(List tasks) { /// Tests that the Flutter module project template works and supports /// adding Flutter to an existing Android app. class ModuleTest { - ModuleTest({this.gradleVersion = '7.6.3'}); + ModuleTest({this.gradleVersion = '7.6.3', Version? agpVersion}) + : agpVersion = agpVersion ?? Version(8, 3, 0); static const String buildTarget = 'module-gradle'; + // gradleVersion is a String because gradle does not follow dart semver + // rules for rc candidates. final String gradleVersion; + final Version agpVersion; final StringBuffer stdout = StringBuffer(); final StringBuffer stderr = StringBuffer(); @@ -63,6 +68,7 @@ class ModuleTest { stderr: stderr, ); }); + print('Created template in $tempDir.'); section('Create package with native assets'); @@ -237,7 +243,7 @@ class ModuleTest { Directory(path.join(hostApp.path, 'gradle', 'wrapper')), ); - // Modify gradle version to passed in version. + // Modify gradle version to the passed in version. // This is somehow the wrong file. final File gradleWrapperProperties = File( path.join(hostApp.path, 'gradle', 'wrapper', 'gradle-wrapper.properties'), @@ -247,6 +253,15 @@ class ModuleTest { section(propertyContent); await gradleWrapperProperties.writeAsString(propertyContent, flush: true); + // Modify AGP version to the passed in version. + final File topBuildDotGradle = File(path.join(hostApp.path, 'build.gradle')); + String topBuildContent = await topBuildDotGradle.readAsString(); + topBuildContent = topBuildContent.replaceFirst('REPLACEME', agpVersion.toString()); + section(topBuildContent); + await topBuildDotGradle.writeAsString(topBuildContent, flush: true); + + final bool greaterThanOrEqualToGradle83 = agpVersion.compareTo(Version(8, 3, 0)) >= 0; + section('Build debug host APK'); await inDirectory(hostApp, () async { @@ -300,7 +315,7 @@ class ModuleTest { ); } - section('Check file access modes for read-only asset from Flutter module'); + section('Check file access modes for Debug read-only asset from Flutter module'); final String readonlyDebugAssetFilePath = path.joinAll([ hostApp.path, @@ -309,13 +324,15 @@ class ModuleTest { 'intermediates', 'assets', 'debug', + ...greaterThanOrEqualToGradle83 ? ['mergeDebugAssets'] : [], 'flutter_assets', 'assets', 'read-only.txt', ]); + // ./app/build/intermediates/assets/debug/mergeDebugAssets/flutter_assets/assets/read-only.txt final File readonlyDebugAssetFile = File(readonlyDebugAssetFilePath); if (!exists(readonlyDebugAssetFile)) { - return TaskResult.failure('Failed to copy read-only asset file'); + return TaskResult.failure('Failed to copy read-only debug asset file'); } String modes = readonlyDebugAssetFile.statSync().modeString(); @@ -393,7 +410,7 @@ class ModuleTest { ); } - section('Check file access modes for read-only asset from Flutter module'); + section('Check file access modes for release read-only asset from Flutter module'); final String readonlyReleaseAssetFilePath = path.joinAll([ hostApp.path, @@ -402,13 +419,14 @@ class ModuleTest { 'intermediates', 'assets', 'release', + ...greaterThanOrEqualToGradle83 ? ['mergeReleaseAssets'] : [], 'flutter_assets', 'assets', 'read-only.txt', ]); final File readonlyReleaseAssetFile = File(readonlyReleaseAssetFilePath); if (!exists(readonlyReleaseAssetFile)) { - return TaskResult.failure('Failed to copy read-only asset file'); + return TaskResult.failure('Failed to copy read-only release asset file'); } modes = readonlyReleaseAssetFile.statSync().modeString(); @@ -437,8 +455,11 @@ class ModuleTest { Future main() async { await task( combine([ - ModuleTest(gradleVersion: '8.4').call, - ModuleTest(gradleVersion: '8.4-rc-3').call, + // 3 tests comes close to timeout. + // Pre AGP 8.3 + ModuleTest(gradleVersion: '8.4', agpVersion: Version.parse('8.1.0')).call, + // Post AGP 8.3 + rc candidates can work + ModuleTest(gradleVersion: '8.13-rc-1', agpVersion: Version.parse('8.8.1')).call, ]), ); } diff --git a/dev/integration_tests/pure_android_host_apps/android_host_app_v2_embedding/build.gradle b/dev/integration_tests/pure_android_host_apps/android_host_app_v2_embedding/build.gradle index 592d125fbc..8e0242ac57 100644 --- a/dev/integration_tests/pure_android_host_apps/android_host_app_v2_embedding/build.gradle +++ b/dev/integration_tests/pure_android_host_apps/android_host_app_v2_embedding/build.gradle @@ -8,7 +8,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:8.1.0' + classpath 'com.android.tools.build:gradle:REPLACEME' } }