Skip to content

Commit

Permalink
Merge branch 'master' into close-engine-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan authored Feb 29, 2024
2 parents d8dfe29 + 6e0a46f commit 4f39b11
Show file tree
Hide file tree
Showing 59 changed files with 94 additions and 1,938 deletions.
22 changes: 8 additions & 14 deletions .github/workflows/cronet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
package: ['cronet_http', 'cronet_http_embedded']
cronetHttpNoPlay: ['false', 'true']
defaults:
run:
working-directory: pkgs/cronet_http
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93
Expand All @@ -36,24 +39,15 @@ jobs:
- uses: subosito/flutter-action@2783a3f08e1baf891508463f8c6653c258246225
with:
channel: 'stable'
- name: Make cronet_http_embedded copy
if: ${{ matrix.package == 'cronet_http_embedded' }}
run: |
mv pkgs/cronet_http pkgs/cronet_http_embedded
cd pkgs/cronet_http_embedded
flutter pub get && dart tool/prepare_for_embedded.dart
- id: install
name: Install dependencies
working-directory: 'pkgs/${{ matrix.package }}'
run: flutter pub get
- name: Check formatting
working-directory: 'pkgs/${{ matrix.package }}'
run: dart format --output=none --set-exit-if-changed .
if: always() && steps.install.outcome == 'success'
run: dart format --output=none --set-exit-if-changed .
- name: Analyze code
working-directory: 'pkgs/${{ matrix.package }}'
run: flutter analyze --fatal-infos
if: always() && steps.install.outcome == 'success'
run: flutter analyze --fatal-infos
- name: Run tests
uses: reactivecircus/android-emulator-runner@6b0df4b0efb23bb0ec63d881db79aefbc976e4b2
if: always() && steps.install.outcome == 'success'
Expand All @@ -64,6 +58,6 @@ jobs:
# - pkgs/cronet_http/example/android/app/build.gradle
api-level: 21
arch: x86_64
target: ${{ matrix.package == 'cronet_http_embedded' && 'default' || 'google_apis' }}
target: ${{ matrix.cronetHttpNoPlay == 'true' && 'default' || 'google_apis' }}
profile: pixel
script: cd 'pkgs/${{ matrix.package }}/example' && flutter test --timeout=1200s integration_test/
script: cd pkgs/cronet_http/example && flutter test --dart-define=cronetHttpNoPlay=${{ matrix.cronetHttpNoPlay }} --timeout=1200s integration_test/
57 changes: 17 additions & 40 deletions .github/workflows/cupertino.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,37 @@ on:
- main
- master
paths:
- '.github/workflows/cupertino.yml'
- 'pkgs/cupertino_http/**'
- 'pkgs/http_client_conformance_tests/**'
- '.github/workflows/cupertino.yml'
pull_request:
paths:
- '.github/workflows/cupertino.yml'
- 'pkgs/cupertino_http/**'
- 'pkgs/http_client_conformance_tests/**'
- '.github/workflows/cupertino.yml'
schedule:
- cron: "0 0 * * 0"

env:
PUB_ENVIRONMENT: bot.github

jobs:
analyze:
name: Lint and static analysis
runs-on: ubuntu-latest
verify:
name: Format & Analyze & Test
runs-on: macos-latest
defaults:
run:
working-directory: pkgs/cupertino_http
strategy:
matrix:
# Test on the minimum supported flutter version and the latest
# version.
flutter-version: ["3.16.0", "any"]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: subosito/flutter-action@2783a3f08e1baf891508463f8c6653c258246225
with:
flutter-version: ${{ matrix.flutter-version }}
channel: 'stable'
- id: install
name: Install dependencies
Expand All @@ -40,48 +46,19 @@ jobs:
# This approach is simpler than using `find` and excluding that file
# because `dart format` also excludes other file e.g. ones in
# directories start with '.'.
run: >
mv lib/src/native_cupertino_bindings.dart lib/src/native_cupertino_bindings.tmp &&
dart format --output=none --set-exit-if-changed . &&
run: |
mv lib/src/native_cupertino_bindings.dart lib/src/native_cupertino_bindings.tmp
dart format --output=none --set-exit-if-changed .
mv lib/src/native_cupertino_bindings.tmp lib/src/native_cupertino_bindings.dart
if: always() && steps.install.outcome == 'success'
- name: Analyze code
run: flutter analyze --fatal-infos
if: always() && steps.install.outcome == 'success'

test:
# Test package:cupertino_http use flutter integration tests.
needs: analyze
name: "Build and test"
strategy:
matrix:
# Test on the minimum supported flutter version and the latest
# version.
flutter-version: ["3.16.0", "any"]
runs-on: macos-latest
defaults:
run:
working-directory: pkgs/cupertino_http/example
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: futureware-tech/simulator-action@bfa03d93ec9de6dacb0c5553bbf8da8afc6c2ee9
with:
model: 'iPhone 8'
- uses: subosito/flutter-action@2783a3f08e1baf891508463f8c6653c258246225
with:
flutter-version: ${{ matrix.flutter-version }}
channel: 'stable'
- name: Run tests
# TODO: Remove the retries when
# https://github.com/flutter/flutter/issues/121231 is fixed.
# See https://github.com/dart-lang/http/issues/938 for context.
run: |
for i in {1..6}
do
flutter test integration_test/main.dart && break
if [ $i -eq 6 ]
then
exit 1
fi
echo "Retry $i"
done
cd example
flutter pub get
flutter test --timeout=1200s integration_test/
31 changes: 6 additions & 25 deletions .github/workflows/java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ on:
- main
- master
paths:
- 'pkgs/java_http/**'
- 'pkgs/http_client_conformance_tests/**'
- '.github/workflows/java.yml'
- 'pkgs/http_client_conformance_tests/**'
- 'pkgs/java_http/**'
pull_request:
paths:
- 'pkgs/java_http/**'
- 'pkgs/http_client_conformance_tests/**'
- '.github/workflows/java.yml'
- 'pkgs/http_client_conformance_tests/**'
- 'pkgs/java_http/**'
schedule:
# Runs every Sunday at midnight (00:00 UTC).
- cron: "0 0 * * 0"
Expand All @@ -22,8 +22,8 @@ env:
PUB_ENVIRONMENT: bot.github

jobs:
analyze:
name: Lint and static analysis
verify:
name: Format & Analyze & Test
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -33,35 +33,16 @@ jobs:
- uses: subosito/flutter-action@2783a3f08e1baf891508463f8c6653c258246225
with:
channel: 'stable'

- id: install
name: Install dependencies
run: dart pub get

- name: Check formatting
run: dart format --output=none --set-exit-if-changed .
if: always() && steps.install.outcome == 'success'

- name: Analyze code
run: dart analyze --fatal-infos
if: always() && steps.install.outcome == 'success'

test:
needs: analyze
name: Build and test
runs-on: ubuntu-latest
defaults:
run:
working-directory: pkgs/java_http

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: subosito/flutter-action@2783a3f08e1baf891508463f8c6653c258246225
with:
channel: 'stable'

- name: Build jni dynamic libraries
run: dart run jni:setup

- name: Run tests
run: dart test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
.idea/
.vscode/

# Don’t commit the following directories created by pub.
.dart_tool
.packages
pubspec.lock
pubspec_overrides.yaml
3 changes: 2 additions & 1 deletion pkgs/cronet_http/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 1.1.2-wip
## 1.2.0-wip

* Support the Cronet embedding dependency with `--dart-define=cronetHttpNoPlay=true`.
* Fix a bug in the documentation where `isOwned` is used rather than
`closeEngine`.

Expand Down
48 changes: 34 additions & 14 deletions pkgs/cronet_http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@
[![package publisher](https://img.shields.io/pub/publisher/cronet_http.svg)](https://pub.dev/packages/cronet_http/publisher)

An Android Flutter plugin that provides access to the
[Cronet][]
HTTP client.
[Cronet][] HTTP client.

Cronet is available as part of
[Google Play Services][].
Cronet is available as part of [Google Play Services][]
and as [a standalone embedded library][].

This package depends on [Google Play Services][] for its [Cronet][]
implementation.
[`package:cronet_http_embedded`](https://pub.dev/packages/cronet_http_embedded)
is functionally identical to this package but embeds [Cronet][] directly
instead of relying on [Google Play Services][].
This package depends on [Google Play Services][]
for its [Cronet][] implementation.
To use the embedded version of [Cronet][] without [Google Play Services][],
see [Use embedded Cronet](#use-embedded-cronet).

## Motivation

Using [Cronet][], rather than the socket-based [dart:io HttpClient][]
implemententation, has several advantages:
Using [Cronet][], rather than the socket-based
[dart:io HttpClient][] implementation, has several advantages:

1. It automatically supports Android platform features such as HTTP proxies.
2. It supports configurable caching.
Expand Down Expand Up @@ -48,15 +46,37 @@ void main() async {
httpClient = IOClient(HttpClient()..userAgent = 'Book Agent');
}
final response = await client.get(Uri.https(
final response = await client.get(
Uri.https(
'www.googleapis.com',
'/books/v1/volumes',
{'q': 'HTTP', 'maxResults': '40', 'printType': 'books'}));
{'q': 'HTTP', 'maxResults': '40', 'printType': 'books'},
),
);
httpClient.close();
}
```

### Use embedded Cronet

If you want your application to work without [Google Play Services][],
you can instead depend on the `org.chromium.net:cronet-embedded` package
by using `dart-define` to set `cronetHttpNoPlay` is set to `true`.

For example:

```
flutter run --dart-define=cronetHttpNoPlay=true
```

To use the embedded version in `flutter test`:

```
flutter test --dart-define=cronetHttpNoPlay=true
```

[Cronet]: https://developer.android.com/guide/topics/connectivity/cronet/reference/org/chromium/net/package-summary
[dart:io HttpClient]: https://api.dart.dev/stable/dart-io/HttpClient-class.html
[Google Play Services]: https://developers.google.com/android/guides/overview
[a standalone embedded library]: https://mvnrepository.com/artifact/org.chromium.net/cronet-embedded
[dart:io HttpClient]: https://api.dart.dev/stable/dart-io/HttpClient-class.html
[package:http Client]: https://pub.dev/documentation/http/latest/http/Client-class.html
12 changes: 0 additions & 12 deletions pkgs/cronet_http/README_EMBEDDED.md

This file was deleted.

17 changes: 16 additions & 1 deletion pkgs/cronet_http/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ rootProject.allprojects {
}
}

def dartDefines = [
cronetHttpNoPlay: 'false'
]
if (project.hasProperty('dart-defines')) {
def defines = project.property('dart-defines').split(',').collectEntries { entry ->
def pair = new String(entry.decodeBase64(), 'UTF-8').split('=')
[(pair.first()): pair.last()]
}
dartDefines = dartDefines + defines
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

Expand Down Expand Up @@ -65,5 +76,9 @@ android {
}

dependencies {
implementation "com.google.android.gms:play-services-cronet:18.0.1"
if (dartDefines.cronetHttpNoPlay == 'true') {
implementation 'org.chromium.net:cronet-embedded:113.5672.61'
} else {
implementation "com.google.android.gms:play-services-cronet:18.0.1"
}
}
4 changes: 3 additions & 1 deletion pkgs/cronet_http/cronet_http.iml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/build" />
<excludeFolder url="file://$MODULE_DIR$/example/.dart_tool" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart Packages" level="project" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Flutter Plugins" level="project" />
</component>
</module>
</module>
File renamed without changes.
3 changes: 0 additions & 3 deletions pkgs/cronet_http/example/android/local.properties

This file was deleted.

2 changes: 1 addition & 1 deletion pkgs/cronet_http/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: cronet_http
version: 1.1.2-wip
version: 1.2.0-wip
description: >-
An Android Flutter plugin that provides access to the Cronet HTTP client.
repository: https://github.com/dart-lang/http/tree/master/pkgs/cronet_http
Expand Down
Loading

0 comments on commit 4f39b11

Please sign in to comment.