Skip to content

Commit b10f448

Browse files
authored
[cronet_http] Enables CI for cronet_http_embedded (#1070)
1 parent a5b8eec commit b10f448

File tree

11 files changed

+96
-48
lines changed

11 files changed

+96
-48
lines changed

.github/workflows/cronet.yml

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ on:
66
- main
77
- master
88
paths:
9+
- '.github/workflows/**'
910
- 'pkgs/cronet_http/**'
1011
- 'pkgs/http_client_conformance_tests/**'
1112
pull_request:
1213
paths:
14+
- '.github/workflows/**'
1315
- 'pkgs/cronet_http/**'
1416
- 'pkgs/http_client_conformance_tests/**'
1517
schedule:
@@ -19,48 +21,45 @@ env:
1921
PUB_ENVIRONMENT: bot.github
2022

2123
jobs:
22-
analyze:
23-
name: Lint and static analysis
24-
runs-on: ubuntu-latest
25-
defaults:
26-
run:
27-
working-directory: pkgs/cronet_http
24+
verify:
25+
name: Format & Analyze & Test
26+
runs-on: macos-latest
27+
strategy:
28+
matrix:
29+
package: ['cronet_http', 'cronet_http_embedded']
2830
steps:
2931
- uses: actions/checkout@v4
32+
- uses: actions/setup-java@v4
33+
with:
34+
distribution: 'zulu'
35+
java-version: '17'
3036
- uses: subosito/flutter-action@v2
3137
with:
32-
# TODO: Change to 'stable' when a release version of flutter
33-
# pins version 1.21.1 or later of 'package:test'
34-
channel: 'master'
38+
channel: 'stable'
39+
- name: Make cronet_http_embedded copy
40+
if: ${{ matrix.package == 'cronet_http_embedded' }}
41+
run: |
42+
cp -r pkgs/cronet_http pkgs/cronet_http_embedded
43+
cd pkgs/cronet_http_embedded
44+
flutter pub get && dart tool/prepare_for_embedded.dart
3545
- id: install
3646
name: Install dependencies
47+
working-directory: 'pkgs/${{ matrix.package }}'
3748
run: flutter pub get
3849
- name: Check formatting
50+
working-directory: 'pkgs/${{ matrix.package }}'
3951
run: dart format --output=none --set-exit-if-changed .
4052
if: always() && steps.install.outcome == 'success'
4153
- name: Analyze code
54+
working-directory: 'pkgs/${{ matrix.package }}'
4255
run: flutter analyze --fatal-infos
4356
if: always() && steps.install.outcome == 'success'
44-
45-
test:
46-
# Test package:cupertino_http use flutter integration tests.
47-
needs: analyze
48-
name: "Build and test"
49-
runs-on: macos-latest
50-
steps:
51-
- uses: actions/checkout@v4
52-
- uses: actions/setup-java@v4
53-
with:
54-
distribution: 'zulu'
55-
java-version: '17'
56-
- uses: subosito/flutter-action@v2
57-
with:
58-
channel: 'stable'
5957
- name: Run tests
6058
uses: reactivecircus/android-emulator-runner@v2
59+
if: always() && steps.install.outcome == 'success'
6160
with:
6261
api-level: 28
63-
target: playstore
62+
target: ${{ matrix.package == 'cronet_http_embedded' && 'default' || 'playstore' }}
6463
arch: x86_64
6564
profile: pixel
66-
script: cd ./pkgs/cronet_http/example && flutter test --timeout=1200s integration_test/
65+
script: cd 'pkgs/${{ matrix.package }}/example' && flutter test --timeout=1200s integration_test/

pkgs/cronet_http/android/build.gradle

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ group 'io.flutter.plugins.cronet_http'
22
version '1.0-SNAPSHOT'
33

44
buildscript {
5-
ext.kotlin_version = '1.6.10'
5+
ext.kotlin_version = '1.7.21'
66
repositories {
77
google()
88
mavenCentral()
99
}
1010

1111
dependencies {
12-
classpath 'com.android.tools.build:gradle:7.1.2'
12+
classpath 'com.android.tools.build:gradle:7.4.2'
1313
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1414
}
1515
}
@@ -25,6 +25,11 @@ apply plugin: 'com.android.library'
2525
apply plugin: 'kotlin-android'
2626

2727
android {
28+
// Conditional for compatibility with AGP <4.2.
29+
if (project.android.hasProperty("namespace")) {
30+
namespace 'io.flutter.plugins.cronet_http'
31+
}
32+
2833
compileSdkVersion 31
2934

3035
compileOptions {
@@ -41,7 +46,7 @@ android {
4146
}
4247

4348
defaultConfig {
44-
minSdkVersion 16
49+
minSdkVersion 19
4550
}
4651

4752
defaultConfig {

pkgs/cronet_http/example/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ android {
4646
applicationId "io.flutter.cronet_http_example"
4747
// You can update the following values to match your application needs.
4848
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
49-
minSdkVersion flutter.minSdkVersion
49+
minSdkVersion 21
5050
targetSdkVersion flutter.targetSdkVersion
5151
versionCode flutterVersionCode.toInteger()
5252
versionName flutterVersionName
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.example.cronet_http_example">
2+
package="io.flutter.cronet_http_example">
33
<uses-permission android:name="android.permission.INTERNET"/>
44
</manifest>

pkgs/cronet_http/example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.example.cronet_http_example">
2+
package="io.flutter.cronet_http_example">
33
<uses-permission android:name="android.permission.INTERNET"/>
44
<application
55
android:label="cronet_http_example"

pkgs/cronet_http/example/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,25 @@
1515
public final class GeneratedPluginRegistrant {
1616
private static final String TAG = "GeneratedPluginRegistrant";
1717
public static void registerWith(@NonNull FlutterEngine flutterEngine) {
18-
try {
19-
flutterEngine.getPlugins().add(new io.flutter.plugins.cronet_http.CronetHttpPlugin());
20-
} catch(Exception e) {
21-
Log.e(TAG, "Error registering plugin cronet_http, io.flutter.plugins.cronet_http.CronetHttpPlugin", e);
22-
}
2318
try {
2419
flutterEngine.getPlugins().add(new dev.flutter.plugins.integration_test.IntegrationTestPlugin());
25-
} catch(Exception e) {
20+
} catch (Exception e) {
2621
Log.e(TAG, "Error registering plugin integration_test, dev.flutter.plugins.integration_test.IntegrationTestPlugin", e);
2722
}
23+
try {
24+
flutterEngine.getPlugins().add(new com.github.dart_lang.jni.JniPlugin());
25+
} catch (Exception e) {
26+
Log.e(TAG, "Error registering plugin jni, com.github.dart_lang.jni.JniPlugin", e);
27+
}
28+
try {
29+
flutterEngine.getPlugins().add(new io.flutter.plugins.pathprovider.PathProviderPlugin());
30+
} catch (Exception e) {
31+
Log.e(TAG, "Error registering plugin path_provider_android, io.flutter.plugins.pathprovider.PathProviderPlugin", e);
32+
}
33+
try {
34+
flutterEngine.getPlugins().add(new com.tekartik.sqflite.SqflitePlugin());
35+
} catch (Exception e) {
36+
Log.e(TAG, "Error registering plugin sqflite, com.tekartik.sqflite.SqflitePlugin", e);
37+
}
2838
}
2939
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.cronet_http_example
1+
package io.flutter.cronet_http_example
22

33
import io.flutter.embedding.android.FlutterActivity
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.example.cronet_http_example">
2+
package="io.flutter.cronet_http_example">
33
<uses-permission android:name="android.permission.INTERNET"/>
44
</manifest>

pkgs/cronet_http/example/android/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
buildscript {
2-
ext.kotlin_version = '1.6.10'
2+
ext.kotlin_version = '1.7.21'
33
repositories {
44
google()
55
mavenCentral()
66
}
77

88
dependencies {
9-
classpath 'com.android.tools.build:gradle:7.1.2'
9+
classpath 'com.android.tools.build:gradle:7.4.2'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1111
}
1212
}
@@ -26,6 +26,6 @@ subprojects {
2626
project.evaluationDependsOn(':app')
2727
}
2828

29-
task clean(type: Delete) {
29+
tasks.register("clean", Delete) {
3030
delete rootProject.buildDir
3131
}

pkgs/cronet_http/example/android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip

pkgs/cronet_http/tool/prepare_for_embedded.dart

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ final _cronetVersionUri = Uri.https(
4040
'android/maven2/org/chromium/net/group-index.xml',
4141
);
4242

43-
void main() async {
43+
/// Runs `prepare_for_embedded.dart publish` for publishing,
44+
/// or only the Android dependency will be modified.
45+
void main(List<String> args) async {
4446
if (Directory.current.path.endsWith('tool')) {
4547
_packageDirectory = Directory.current.parent;
4648
} else {
@@ -51,6 +53,8 @@ void main() async {
5153
updateCronetDependency(latestVersion);
5254
updatePubSpec();
5355
updateReadme();
56+
updateImports();
57+
updateEntryPoint();
5458
}
5559

5660
Future<String> _getLatestCronetVersion() async {
@@ -69,7 +73,7 @@ Future<String> _getLatestCronetVersion() async {
6973
return versions.last;
7074
}
7175

72-
/// Update android/build.gradle
76+
/// Update android/build.gradle.
7377
void updateCronetDependency(String latestVersion) {
7478
final fBuildGradle = File('${_packageDirectory.path}/android/build.gradle');
7579
final gradleContent = fBuildGradle.readAsStringSync();
@@ -88,18 +92,48 @@ void updateCronetDependency(String latestVersion) {
8892
fBuildGradle.writeAsStringSync(newGradleContent);
8993
}
9094

91-
/// Update pubspec.yaml
95+
/// Update pubspec.yaml and example/pubspec.yaml.
9296
void updatePubSpec() {
97+
print('Updating pubspec.yaml');
9398
final fPubspec = File('${_packageDirectory.path}/pubspec.yaml');
9499
final yamlEditor = YamlEditor(fPubspec.readAsStringSync())
95100
..update(['name'], _packageName)
96101
..update(['description'], _packageDescription);
97102
fPubspec.writeAsStringSync(yamlEditor.toString());
103+
print('Updating example/pubspec.yaml');
104+
final examplePubspec = File('${_packageDirectory.path}/example/pubspec.yaml');
105+
final replaced = examplePubspec
106+
.readAsStringSync()
107+
.replaceAll('cronet_http:', 'cronet_http_embedded:');
108+
examplePubspec.writeAsStringSync(replaced);
98109
}
99110

100-
/// Move README_EMBEDDED.md to replace README.md
111+
/// Move README_EMBEDDED.md to replace README.md.
101112
void updateReadme() {
113+
print('Updating README.md from README_EMBEDDED.md');
102114
File('${_packageDirectory.path}/README.md').deleteSync();
103115
File('${_packageDirectory.path}/README_EMBEDDED.md')
104116
.renameSync('${_packageDirectory.path}/README.md');
105117
}
118+
119+
void updateImports() {
120+
print('Updating imports in Dart files');
121+
for (final file in _packageDirectory.listSync(recursive: true)) {
122+
if (file is File && file.path.endsWith('.dart')) {
123+
final updatedSource = file.readAsStringSync().replaceAll(
124+
'package:cronet_http/cronet_http.dart',
125+
'package:cronet_http_embedded/cronet_http_embedded.dart',
126+
);
127+
file.writeAsStringSync(updatedSource);
128+
}
129+
}
130+
}
131+
132+
void updateEntryPoint() {
133+
print('Renaming cronet_http.dart to cronet_http_embedded.dart');
134+
File(
135+
'${_packageDirectory.path}/lib/cronet_http.dart',
136+
).renameSync(
137+
'${_packageDirectory.path}/lib/cronet_http_embedded.dart',
138+
);
139+
}

0 commit comments

Comments
 (0)