Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the "play-services-cronet" dependency in the example app when building package:cronet_http_embedded #1103

Merged
merged 6 commits into from
Jan 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions pkgs/cronet_http/tool/prepare_for_embedded.dart
Original file line number Diff line number Diff line change
@@ -42,6 +42,14 @@ final _cronetVersionUri = Uri.https(
'dl.google.com',
'android/maven2/org/chromium/net/group-index.xml',
);
// Finds the Google Play Services Cronet dependency line. For example:
// ' implementation "com.google.android.gms:play-services-cronet:18.0.1"'
final implementationRegExp = RegExp(
'^\\s*implementation [\'"]'
'$_gmsDependencyName'
':\\d+.\\d+.\\d+[\'"]',
multiLine: true,
);

void main(List<String> args) async {
if (Directory.current.path.endsWith('tool')) {
@@ -51,7 +59,8 @@ void main(List<String> args) async {
}

final latestVersion = await _getLatestCronetVersion();
updateCronetDependency(latestVersion);
updateBuildGradle(latestVersion);
updateExampleBuildGradle();
updatePubSpec();
updateReadme();
updateLibraryName();
@@ -75,22 +84,30 @@ Future<String> _getLatestCronetVersion() async {
}

/// Update android/build.gradle.
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,
);
void updateBuildGradle(String latestVersion) {
final buildGradle = File('${_packageDirectory.path}/android/build.gradle');
final gradleContent = buildGradle.readAsStringSync();
final newImplementation = '$_embeddedDependencyName:$latestVersion';
print('Patching $newImplementation');
print('Updating ${buildGradle.path}: adding $newImplementation');
final newGradleContent = gradleContent.replaceAll(
implementationRegExp,
' implementation "$newImplementation"',
);
fBuildGradle.writeAsStringSync(newGradleContent);
buildGradle.writeAsStringSync(newGradleContent);
}

/// Remove the cronet reference from ./example/android/app/build.gradle.
void updateExampleBuildGradle() {
final buildGradle =
File('${_packageDirectory.path}/example/android/app/build.gradle');
final gradleContent = buildGradle.readAsStringSync();

print('Updating ${buildGradle.path}: removing cronet reference');
final newGradleContent = gradleContent.replaceAll(
implementationRegExp,
' // NOTE: removed in package:cronet_http_embedded',
);
buildGradle.writeAsStringSync(newGradleContent);
}

/// Update pubspec.yaml and example/pubspec.yaml.