webkit/README.md
See this page rendered in Gitiles markdown.
The Jetpack Webkit library (also known as AndroidX Webkit) is a static library you can add to your Android application in order to use android.webkit APIs that are not available for older platform versions, as well as access new features available in Android System WebView.
The Jetpack Webkit library enables developers to access new features that are
available in the installed version of Android System WebView, even if those
features are not exposed through the
android.webkit
framework API. It does this by dynamically checking the set of available
features through the
WebViewFeature
class.
You should take care to always check feature availability before calling an API, as you otherwise risk a runtime crash if the WebView provider installed on a users device doesn't support the feature in question. This is most likely to happen if the user in question has not yet updated to a version of Android System WebView that supports the feature, but in rare cases WebView may also stop supporting a previously supported feature as part of an API deprecation.
Add this to your build.gradle file:
dependencies {
implementation "androidx.webkit:webkit:1.14.0"
}
Important: replace 1.14.0 with the latest version from
https://developer.android.com/jetpack/androidx/releases/webkit.
Please check out the WebView samples on GitHub for a showcase of a handful of Jetpack Webkit APIs.
For more APIs, check out the sample app in the AndroidX repo.
If you find bugs in the Jetpack Webkit library or want to request new features, please file a ticket.
The Jetpack Webkit library contains a number of experimental APIs. These APIs
will be marked with annotations that use the
@RequiresOptIn
annotation. We encourage you to try out these APIs in your application and file
feedback if you encounter any issues with the API in the
current shape.
When using an experimental API, you should keep the following points in mind:
androidx.webkit:webkit:1.14.0, then the stable version
of WebView will continue to support the API until
androidx.webkit:webkit:1.15.0 has been released, but after the next release
the support may then be dropped in WebView versions, depending on the
evolution of the API.If you're trying to modify the Jetpack Webkit library, or apply local changes to the library, you can do so like so:
cd frameworks/support/
# Build the library/compile changes
./gradlew :webkit:webkit:assembleDebug
# Run integration tests with the WebView installed on the device
# using this convenience script:
webkit/run_instrumentation_tests.sh
# or run the tests directly:
./gradlew webkit:integration-tests:instrumentation:connectedAndroidTest \
-Pandroid.testInstrumentationRunnerArguments.webview-version=factory
# Update API files (only necessary if you changed public APIs)
./gradlew :webkit:webkit:updateApi
For more a detailed developer guide, Googlers should read http://go/wvsl-contribute.
The instrumentation tests for Jetpack Webkit are located in the
:webkit:integration-tests:instrumentation project. The tests have been split
out into a separate project to facilitate testing against different targetSdk
versions.
Any new tests should be added to that project. To run the test, use the command above.