Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into more-config2
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan committed Dec 21, 2023
2 parents 7199b11 + 15ec3ba commit e6ba2f1
Show file tree
Hide file tree
Showing 20 changed files with 216 additions and 78 deletions.
56 changes: 29 additions & 27 deletions .github/workflows/cronet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ on:
- main
- master
paths:
- '.github/workflows/cronet.yaml'
- 'pkgs/cronet_http/**'
- 'pkgs/http_client_conformance_tests/**'
pull_request:
paths:
- '.github/workflows/cronet.yaml'
- 'pkgs/cronet_http/**'
- 'pkgs/http_client_conformance_tests/**'
schedule:
Expand All @@ -19,48 +21,48 @@ env:
PUB_ENVIRONMENT: bot.github

jobs:
analyze:
name: Lint and static analysis
runs-on: ubuntu-latest
defaults:
run:
working-directory: pkgs/cronet_http
verify:
name: Format & Analyze & Test
runs-on: macos-latest
strategy:
matrix:
package: ['cronet_http', 'cronet_http_embedded']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
- uses: subosito/flutter-action@v2
with:
# TODO: Change to 'stable' when a release version of flutter
# pins version 1.21.1 or later of 'package:test'
channel: 'master'
channel: 'stable'
- name: Make cronet_http_embedded copy
if: ${{ matrix.package == 'cronet_http_embedded' }}
run: |
cp -r 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'
- name: Analyze code
working-directory: 'pkgs/${{ matrix.package }}'
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"
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
- name: Run tests
uses: reactivecircus/android-emulator-runner@v2
if: always() && steps.install.outcome == 'success'
with:
# api-level/minSdkVersion should be help in sync in:
# - .github/workflows/cronet.yml
# - pkgs/cronet_http/android/build.gradle
# - pkgs/cronet_http/example/android/app/build.gradle
api-level: 28
target: playstore
arch: x86_64
target: ${{ matrix.package == 'cronet_http_embedded' && 'google_apis' || 'playstore' }}
profile: pixel
script: cd ./pkgs/cronet_http/example && flutter test --timeout=1200s integration_test/
script: cd 'pkgs/${{ matrix.package }}/example' && flutter test --timeout=1200s integration_test/
4 changes: 4 additions & 0 deletions pkgs/cronet_http/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.0

* No functional changes.

## 0.4.2

* Require `package:jni >= 0.7.2` to remove a potential buffer overflow.
Expand Down
80 changes: 55 additions & 25 deletions pkgs/cronet_http/README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,61 @@
[![pub package](https://img.shields.io/pub/v/cronet_http.svg)](https://pub.dev/packages/cronet_http)
[![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](https://developer.android.com/guide/topics/connectivity/cronet/reference/org/chromium/net/package-summary)
[Cronet][]
HTTP client.

Cronet is available as part of
[Google Play Services](https://developers.google.com/android/guides/overview).
[Google Play Services][].

This package depends on
[Google Play Services](https://developers.google.com/android/guides/overview)
for its Cronet implementation.
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](https://developers.google.com/android/guides/overview).

## Status: Experimental

**NOTE**: This package is currently experimental and published under the
[labs.dart.dev](https://dart.dev/dart-team-packages) pub publisher in order to
solicit feedback.

For packages in the labs.dart.dev publisher we generally plan to either graduate
the package into a supported publisher (dart.dev, tools.dart.dev) after a period
of feedback and iteration, or discontinue the package. These packages have a
much higher expected rate of API and breaking changes.

Your feedback is valuable and will help us evolve this package.
For general feedback and suggestions please comment in the
[feedback issue](https://github.com/dart-lang/http/issues/764).
For bugs, please file an issue in the
[bug tracker](https://github.com/dart-lang/http/issues).
is functionally identical to this package but embeds [Cronet][] directly
instead of relying on [Google Play Services][].

## Motivation

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

1. It automatically supports Android platform features such as HTTP proxies.
2. It supports configurable caching.
3. It supports more HTTP features such as HTTP/3.

## Using

The easiest way to use this library is via the the high-level interface
defined by [package:http Client][].

This approach allows the same HTTP code to be used on all platforms, while
still allowing platform-specific setup.

```dart
import 'package:cronet_http/cronet_http.dart';
import 'package:http/http.dart';
import 'package:http/io_client.dart';
void main() async {
late Client httpClient;
if (Platform.isAndroid) {
final engine = CronetEngine.build(
cacheMode: CacheMode.memory,
cacheMaxSize: 2 * 1024 * 1024,
userAgent: 'Book Agent');
httpClient = CronetClient.fromCronetEngine(engine);
} else {
httpClient = IOClient(HttpClient()..userAgent = 'Book Agent');
}
final response = await client.get(Uri.https(
'www.googleapis.com',
'/books/v1/volumes',
{'q': 'HTTP', 'maxResults': '40', 'printType': 'books'}));
}
```

[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
[package:http Client]: https://pub.dev/documentation/http/latest/http/Client-class.html
15 changes: 12 additions & 3 deletions pkgs/cronet_http/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ group 'io.flutter.plugins.cronet_http'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.7.21'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -25,6 +25,11 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
// Conditional for compatibility with AGP <4.2.
if (project.android.hasProperty("namespace")) {
namespace 'io.flutter.plugins.cronet_http'
}

compileSdkVersion 31

compileOptions {
Expand All @@ -41,7 +46,11 @@ android {
}

defaultConfig {
minSdkVersion 16
// api-level/minSdkVersion should be help in sync in:
// - .github/workflows/cronet.yml
// - pkgs/cronet_http/android/build.gradle
// - pkgs/cronet_http/example/android/app/build.gradle
minSdkVersion 28
}

defaultConfig {
Expand Down
6 changes: 5 additions & 1 deletion pkgs/cronet_http/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ android {
applicationId "io.flutter.cronet_http_example"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion
// api-level/minSdkVersion should be help in sync in:
// - .github/workflows/cronet.yml
// - pkgs/cronet_http/android/build.gradle
// - pkgs/cronet_http/example/android/app/build.gradle
minSdkVersion 28
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cronet_http_example">
package="io.flutter.cronet_http_example">
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cronet_http_example">
package="io.flutter.cronet_http_example">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:label="cronet_http_example"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,25 @@
public final class GeneratedPluginRegistrant {
private static final String TAG = "GeneratedPluginRegistrant";
public static void registerWith(@NonNull FlutterEngine flutterEngine) {
try {
flutterEngine.getPlugins().add(new io.flutter.plugins.cronet_http.CronetHttpPlugin());
} catch(Exception e) {
Log.e(TAG, "Error registering plugin cronet_http, io.flutter.plugins.cronet_http.CronetHttpPlugin", e);
}
try {
flutterEngine.getPlugins().add(new dev.flutter.plugins.integration_test.IntegrationTestPlugin());
} catch(Exception e) {
} catch (Exception e) {
Log.e(TAG, "Error registering plugin integration_test, dev.flutter.plugins.integration_test.IntegrationTestPlugin", e);
}
try {
flutterEngine.getPlugins().add(new com.github.dart_lang.jni.JniPlugin());
} catch (Exception e) {
Log.e(TAG, "Error registering plugin jni, com.github.dart_lang.jni.JniPlugin", e);
}
try {
flutterEngine.getPlugins().add(new io.flutter.plugins.pathprovider.PathProviderPlugin());
} catch (Exception e) {
Log.e(TAG, "Error registering plugin path_provider_android, io.flutter.plugins.pathprovider.PathProviderPlugin", e);
}
try {
flutterEngine.getPlugins().add(new com.tekartik.sqflite.SqflitePlugin());
} catch (Exception e) {
Log.e(TAG, "Error registering plugin sqflite, com.tekartik.sqflite.SqflitePlugin", e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.cronet_http_example
package io.flutter.cronet_http_example

import io.flutter.embedding.android.FlutterActivity

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cronet_http_example">
package="io.flutter.cronet_http_example">
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
6 changes: 3 additions & 3 deletions pkgs/cronet_http/example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.7.21'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
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: 0.4.2
version: 1.0.0
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 e6ba2f1

Please sign in to comment.