From 23b50abc02b45c3f2687a2ef5f5baa552f7a0265 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Tue, 2 Jan 2024 12:46:32 -0800 Subject: [PATCH 1/3] Hard code the embedded cronet version --- .../tool/prepare_for_embedded.dart | 28 +++---------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/pkgs/cronet_http/tool/prepare_for_embedded.dart b/pkgs/cronet_http/tool/prepare_for_embedded.dart index 3442bc6843..302917bbf9 100644 --- a/pkgs/cronet_http/tool/prepare_for_embedded.dart +++ b/pkgs/cronet_http/tool/prepare_for_embedded.dart @@ -25,12 +25,13 @@ library; import 'dart:io'; -import 'package:http/http.dart' as http; -import 'package:xml/xml.dart'; import 'package:yaml_edit/yaml_edit.dart'; late final Directory _packageDirectory; +// For the latest version, see: +// https://mvnrepository.com/artifact/org.chromium.net/cronet-embedded +const _cronetEmbeddedVersion = "113.5672.61"; const _gmsDependencyName = 'com.google.android.gms:play-services-cronet'; const _embeddedDependencyName = 'org.chromium.net:cronet-embedded'; const _packageName = 'cronet_http_embedded'; @@ -38,10 +39,6 @@ const _packageDescription = 'An Android Flutter plugin that ' 'provides access to the Cronet HTTP client. ' 'Identical to package:cronet_http except that it embeds Cronet ' 'rather than relying on Google Play Services.'; -final _cronetVersionUri = Uri.https( - 'dl.google.com', - 'android/maven2/org/chromium/net/group-index.xml', -); void main(List args) async { if (Directory.current.path.endsWith('tool')) { @@ -50,30 +47,13 @@ void main(List args) async { _packageDirectory = Directory.current; } - final latestVersion = await _getLatestCronetVersion(); - updateCronetDependency(latestVersion); + updateCronetDependency(_cronetEmbeddedVersion); updatePubSpec(); updateReadme(); updateLibraryName(); updateImports(); } -Future _getLatestCronetVersion() async { - final response = await http.get(_cronetVersionUri); - final parsedXml = XmlDocument.parse(response.body); - final embeddedNode = parsedXml.children - .singleWhere((e) => e is XmlElement) - .children - .singleWhere((e) => e is XmlElement && e.name.local == 'cronet-embedded'); - final stableVersionReg = RegExp(r'^\d+.\d+.\d+$'); - final versions = embeddedNode.attributes - .singleWhere((e) => e.name.local == 'versions') - .value - .split(',') - .where((e) => stableVersionReg.stringMatch(e) == e); - return versions.last; -} - /// Update android/build.gradle. void updateCronetDependency(String latestVersion) { final fBuildGradle = File('${_packageDirectory.path}/android/build.gradle'); From ffa890e72ffc7d86efd4a69d0a318ee921c29d0c Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Tue, 2 Jan 2024 12:51:19 -0800 Subject: [PATCH 2/3] Single quotes --- pkgs/cronet_http/tool/prepare_for_embedded.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/cronet_http/tool/prepare_for_embedded.dart b/pkgs/cronet_http/tool/prepare_for_embedded.dart index 302917bbf9..449d7f1041 100644 --- a/pkgs/cronet_http/tool/prepare_for_embedded.dart +++ b/pkgs/cronet_http/tool/prepare_for_embedded.dart @@ -31,7 +31,7 @@ late final Directory _packageDirectory; // For the latest version, see: // https://mvnrepository.com/artifact/org.chromium.net/cronet-embedded -const _cronetEmbeddedVersion = "113.5672.61"; +const _cronetEmbeddedVersion = '113.5672.61'; const _gmsDependencyName = 'com.google.android.gms:play-services-cronet'; const _embeddedDependencyName = 'org.chromium.net:cronet-embedded'; const _packageName = 'cronet_http_embedded'; From 25df74497cdb0738d568cdda6f75e9b0787b24a3 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Tue, 2 Jan 2024 13:05:56 -0800 Subject: [PATCH 3/3] Update prepare_for_embedded.dart --- .../tool/prepare_for_embedded.dart | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/pkgs/cronet_http/tool/prepare_for_embedded.dart b/pkgs/cronet_http/tool/prepare_for_embedded.dart index 449d7f1041..edbedb66b5 100644 --- a/pkgs/cronet_http/tool/prepare_for_embedded.dart +++ b/pkgs/cronet_http/tool/prepare_for_embedded.dart @@ -39,6 +39,12 @@ const _packageDescription = 'An Android Flutter plugin that ' 'provides access to the Cronet HTTP client. ' 'Identical to package:cronet_http except that it embeds Cronet ' 'rather than relying on Google Play Services.'; +final implementationRegExp = RegExp( + '^\\s*implementation [\'"]' + '$_gmsDependencyName' + ':\\d+.\\d+.\\d+[\'"]', + multiLine: true, +); void main(List args) async { if (Directory.current.path.endsWith('tool')) { @@ -48,6 +54,7 @@ void main(List args) async { } updateCronetDependency(_cronetEmbeddedVersion); + update2(); updatePubSpec(); updateReadme(); updateLibraryName(); @@ -58,12 +65,6 @@ void main(List args) async { void updateCronetDependency(String latestVersion) { final fBuildGradle = File('${_packageDirectory.path}/android/build.gradle'); final gradleContent = fBuildGradle.readAsStringSync(); - final implementationRegExp = RegExp( - '^\\s*implementation [\'"]' - '$_gmsDependencyName' - ':\\d+.\\d+.\\d+[\'"]', - multiLine: true, - ); final newImplementation = '$_embeddedDependencyName:$latestVersion'; print('Patching $newImplementation'); final newGradleContent = gradleContent.replaceAll( @@ -73,6 +74,17 @@ void updateCronetDependency(String latestVersion) { fBuildGradle.writeAsStringSync(newGradleContent); } +void update2() { + final fBuildGradle = + File('${_packageDirectory.path}/example/android/app/build.gradle'); + final gradleContent = fBuildGradle.readAsStringSync(); + final newGradleContent = gradleContent.replaceAll( + implementationRegExp, + '', + ); + fBuildGradle.writeAsStringSync(newGradleContent); +} + /// Update pubspec.yaml and example/pubspec.yaml. void updatePubSpec() { print('Updating pubspec.yaml');