Skip to content

Commit 6003bfe

Browse files
[webview_flutter_android] Updates plugin to use ProxyApiss (#7794)
1 parent 0e73a05 commit 6003bfe

File tree

125 files changed

+17809
-23523
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+17809
-23523
lines changed

packages/webview_flutter/webview_flutter_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 4.1.0
2+
3+
* Updates internal API wrapper to use `ProxyApi`s.
4+
15
## 4.0.3
26

37
* Bumps androidx.annotation:annotation from 1.8.2 to 1.9.1.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Contributing to `webview_flutter_android`
2+
3+
Please start by taking a look at the general guide to contributing to the `flutter/packages` repo:
4+
https://github.com/flutter/packages/blob/main/CONTRIBUTING.md
5+
6+
## Package Structure
7+
8+
This plugin serves as a platform implementation plugin as outlined in [federated plugins](https://docs.flutter.dev/packages-and-plugins/developing-packages#federated-plugins).
9+
The sections below will provide an overview of how this plugin implements this portion with Android.
10+
11+
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).
12+
13+
### Quick Overview
14+
15+
This plugin implements the platform interface provided by `webview_flutter_platform_interface` using
16+
the native WebKit APIs for Android.
17+
18+
#### SDK Wrappers
19+
20+
To access native APIS, this plugins uses Dart wrappers of the native library. The native library is
21+
wrapped using using the `ProxyApi` feature from the `pigeon` package.
22+
23+
The wrappers for the native library can be updated and modified by changing `pigeons/android_webkit.dart`.
24+
25+
The generated files are located:
26+
* `lib/src/android_webkit.g.dart`
27+
* `android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt`
28+
29+
To update the wrapper, follow the steps below:
30+
31+
##### 1. Ensure the project has been built at least once
32+
33+
Run `flutter build apk --debug` in `example/`.
34+
35+
##### 2. Make changes to the respective pigeon file that matches the native SDK
36+
37+
* Android Dependency: https://developer.android.com/reference/android/webkit/package-summary
38+
* Pigeon file to update: `pigeons/android_webkit.dart`
39+
40+
##### 3. Run the code generator from the terminal
41+
42+
Run: `dart run pigeon --input pigeons/android_webkit.dart`
43+
44+
##### 4. Update the generated APIs in native code
45+
46+
Running the `flutter build` command from step 1 again should provide build errors and indicate what
47+
needs to be done. Alternatively, it can be easier to update native code with the platform's specific
48+
IDE:
49+
50+
Open `example/android/` in a separate Android Studio project.
51+
52+
##### 5. Write API tests
53+
54+
Assuming a non-static method or constructor was added to the native wrapper, a native test will need
55+
to be added.
56+
57+
Tests location: `android/src/test/java/io/flutter/plugins/webviewflutter/`
58+
59+
## Important Notes
60+
61+
### Calling `WebView.destroy()` after Dart Instance is Garbage Collected
62+
63+
To avoid a potentially breaking change, the code in `android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt`
64+
needs to be updated after the pigeon generator is run. Please add
65+
66+
```kotlin
67+
val instance: Any? = getInstance(identifier)
68+
if (instance is WebViewProxyApi.WebViewPlatformView) {
69+
instance.destroy()
70+
}
71+
```
72+
73+
to `AndroidWebkitLibraryPigeonInstanceManager.remove`. The current implementation of the native
74+
code doesn't currently support handling when the Dart instance is garbage collected.

packages/webview_flutter/webview_flutter_android/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,9 @@ androidController.setCustomWidgetCallbacks(
7373
);
7474
```
7575

76+
## Contributing
77+
78+
For information on contributing to this plugin, see [`CONTRIBUTING.md`](CONTRIBUTING.md).
79+
7680
[1]: https://pub.dev/packages/webview_flutter
7781
[2]: https://flutter.dev/to/endorsed-federated-plugin

packages/webview_flutter/webview_flutter_android/android/build.gradle

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ group 'io.flutter.plugins.webviewflutter'
22
version '1.0-SNAPSHOT'
33

44
buildscript {
5+
ext.kotlin_version = '1.9.10'
56
repositories {
67
google()
78
mavenCentral()
89
}
910

1011
dependencies {
1112
classpath 'com.android.tools.build:gradle:8.0.0'
13+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1214
}
1315
}
1416

@@ -20,11 +22,21 @@ rootProject.allprojects {
2022
}
2123

2224
apply plugin: 'com.android.library'
25+
apply plugin: 'kotlin-android'
2326

2427
android {
2528
namespace 'io.flutter.plugins.webviewflutter'
2629
compileSdk 34
2730

31+
compileOptions {
32+
sourceCompatibility JavaVersion.VERSION_11
33+
targetCompatibility JavaVersion.VERSION_11
34+
}
35+
36+
kotlinOptions {
37+
jvmTarget = '11'
38+
}
39+
2840
defaultConfig {
2941
minSdkVersion 21
3042
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -44,11 +56,6 @@ android {
4456
testImplementation 'androidx.test:core:1.3.0'
4557
}
4658

47-
compileOptions {
48-
sourceCompatibility JavaVersion.VERSION_11
49-
targetCompatibility JavaVersion.VERSION_11
50-
}
51-
5259
testOptions {
5360
unitTests.includeAndroidResources = true
5461
unitTests.returnDefaultValues = true

0 commit comments

Comments
 (0)