Skip to content

Commit

Permalink
[webview_flutter_android] Updates plugin to use ProxyApiss (#7794)
Browse files Browse the repository at this point in the history
  • Loading branch information
bparrishMines authored Nov 19, 2024
1 parent 0e73a05 commit 6003bfe
Show file tree
Hide file tree
Showing 125 changed files with 17,809 additions and 23,523 deletions.
4 changes: 4 additions & 0 deletions packages/webview_flutter/webview_flutter_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.1.0

* Updates internal API wrapper to use `ProxyApi`s.

## 4.0.3

* Bumps androidx.annotation:annotation from 1.8.2 to 1.9.1.
Expand Down
74 changes: 74 additions & 0 deletions packages/webview_flutter/webview_flutter_android/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Contributing to `webview_flutter_android`

Please start by taking a look at the general guide to contributing to the `flutter/packages` repo:
https://github.com/flutter/packages/blob/main/CONTRIBUTING.md

## Package Structure

This plugin serves as a platform implementation plugin as outlined in [federated plugins](https://docs.flutter.dev/packages-and-plugins/developing-packages#federated-plugins).
The sections below will provide an overview of how this plugin implements this portion with Android.

For making changes to this package, please take a look at [changing federated plugins](https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins).

### Quick Overview

This plugin implements the platform interface provided by `webview_flutter_platform_interface` using
the native WebKit APIs for Android.

#### SDK Wrappers

To access native APIS, this plugins uses Dart wrappers of the native library. The native library is
wrapped using using the `ProxyApi` feature from the `pigeon` package.

The wrappers for the native library can be updated and modified by changing `pigeons/android_webkit.dart`.

The generated files are located:
* `lib/src/android_webkit.g.dart`
* `android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt`

To update the wrapper, follow the steps below:

##### 1. Ensure the project has been built at least once

Run `flutter build apk --debug` in `example/`.

##### 2. Make changes to the respective pigeon file that matches the native SDK

* Android Dependency: https://developer.android.com/reference/android/webkit/package-summary
* Pigeon file to update: `pigeons/android_webkit.dart`

##### 3. Run the code generator from the terminal

Run: `dart run pigeon --input pigeons/android_webkit.dart`

##### 4. Update the generated APIs in native code

Running the `flutter build` command from step 1 again should provide build errors and indicate what
needs to be done. Alternatively, it can be easier to update native code with the platform's specific
IDE:

Open `example/android/` in a separate Android Studio project.

##### 5. Write API tests

Assuming a non-static method or constructor was added to the native wrapper, a native test will need
to be added.

Tests location: `android/src/test/java/io/flutter/plugins/webviewflutter/`

## Important Notes

### Calling `WebView.destroy()` after Dart Instance is Garbage Collected

To avoid a potentially breaking change, the code in `android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt`
needs to be updated after the pigeon generator is run. Please add

```kotlin
val instance: Any? = getInstance(identifier)
if (instance is WebViewProxyApi.WebViewPlatformView) {
instance.destroy()
}
```

to `AndroidWebkitLibraryPigeonInstanceManager.remove`. The current implementation of the native
code doesn't currently support handling when the Dart instance is garbage collected.
4 changes: 4 additions & 0 deletions packages/webview_flutter/webview_flutter_android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,9 @@ androidController.setCustomWidgetCallbacks(
);
```

## Contributing

For information on contributing to this plugin, see [`CONTRIBUTING.md`](CONTRIBUTING.md).

[1]: https://pub.dev/packages/webview_flutter
[2]: https://flutter.dev/to/endorsed-federated-plugin
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ group 'io.flutter.plugins.webviewflutter'
version '1.0-SNAPSHOT'

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

dependencies {
classpath 'com.android.tools.build:gradle:8.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

Expand All @@ -20,11 +22,21 @@ rootProject.allprojects {
}

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

android {
namespace 'io.flutter.plugins.webviewflutter'
compileSdk 34

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = '11'
}

defaultConfig {
minSdkVersion 21
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -44,11 +56,6 @@ android {
testImplementation 'androidx.test:core:1.3.0'
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

testOptions {
unitTests.includeAndroidResources = true
unitTests.returnDefaultValues = true
Expand Down
Loading

0 comments on commit 6003bfe

Please sign in to comment.