使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
JavascriptEngine
启用您的 Android 应用以评估 JavaScript。
最近更新时间 |
稳定版 |
候选版 |
Beta 版 |
Alpha 版 |
2025 年 7 月 2 日 |
1.0.0 |
- |
- |
- |
声明依赖项
如需添加 JavascriptEngine 的依赖项,您必须将 Google Maven 制品库添加到项目中。如需了解详情,请参阅 Google 的 Maven 制品库。
在应用或模块的 build.gradle
文件中添加所需工件的依赖项:
Groovy
dependencies {
implementation "androidx.javascriptengine:javascriptengine:1.0.0"
}
Kotlin
dependencies {
implementation("androidx.javascriptengine:javascriptengine:1.0.0")
}
如需详细了解依赖项,请参阅添加 build 依赖项。
反馈
您的反馈将帮助我们改进 Jetpack。如果您发现了新问题,或对此库有任何改进建议,请告诉我们。创建新问题前,请先查看此库中的现有问题。您可以点击星标按钮,为现有问题投票。
创建新问题
如需了解详情,请参阅问题跟踪器文档。
版本 1.0
版本 1.0.0
2025 年 7 月 2 日
发布了 androidx.javascriptengine:javascriptengine:1.0.0
,该版本与上个 RC 版相比没有明显变化。版本 1.0.0 中包含这些提交内容。
版本 1.0.0-rc01
2025 年 3 月 26 日
发布了 androidx.javascriptengine:javascriptengine:1.0.0-rc01
,该版本与上个 Beta 版相比没有明显变化。版本 1.0.0-rc01 中包含这些提交内容。
版本 1.0.0-beta01
2023 年 11 月 1 日
发布了 androidx.javascriptengine:javascriptengine:1.0.0-beta01
,该版本与上个 Alpha 版相比没有明显变化。版本 1.0.0-beta01 中包含这些提交内容。
版本 1.0.0-alpha07
2023 年 10 月 18 日
发布了 androidx.javascriptengine:javascriptengine:1.0.0-alpha07
。版本 1.0.0-alpha07 中包含这些提交内容。
新功能
- 推出了新 API,允许应用注册回调来处理隔离区崩溃。
API 变更
- 已将
DEFAULT_MAX_HEAP_SIZE
重命名为 AUTOMATIC_MAX_HEAP_SIZE
。(I6d303)
- 已将
FileDescriptorIoException
重命名为 DataInputException
。(Iba4eb)
- 已将
DEFAULT_ISOLATE_HEAP_SIZE
重命名为 DEFAULT_MAX_HEAP_SIZE
。(Iaa16f)
- 移除了无功能的控制台
getSource
和 getTrace
方法。(I4b7a2)
- 取消隐藏
FileDescriptorIoException
(Ic44e6)
- 允许应用注册回调以处理隔离区崩溃。(Iad25f)
版本 1.0.0-alpha06
2023 年 10 月 4 日
发布了 androidx.javascriptengine:javascriptengine:1.0.0-alpha06
。版本 1.0.0-alpha06 中包含这些提交内容。
新功能
- 引入了新的 API,用于从
ParcelFileDescriptor/AssetFileDescriptor
评估 JavaScript,而无需将来源转换为字符串。JavaScriptIsolate
类已实现线程安全。
API 变更
- 将
provideNamedData
更改为抛出异常,而不是返回 false。(I8909a)
- 添加了用于通过 Afds 和 Pfds 评估 JavaScript 的 API (I03e3a)
- 使
MemoryLimitExceededException
和 SandboxDeadException
成为 IsolateTerminatedException
的子类 (Icf359)
- 移除了面向公众的 API
evaluateJavaScriptAsync(@NonNull byte[] code)
(I4b3ac)
bug 修复
- 使
JavaScriptIsolate
具有线程安全性。(Ib28e0)
版本 1.0.0-alpha05
2023 年 4 月 5 日
发布了 androidx.javascriptengine:javascriptengine:1.0.0-alpha05
。版本 1.0.0-alpha05 中包含这些提交内容。
API 变更
版本 1.0.0-alpha04
2023 年 2 月 22 日
发布了 androidx.javascriptengine:javascriptengine:1.0.0-alpha04
。版本 1.0.0-alpha04 中包含这些提交内容。
bug 修复
- 修复了沙盒化进程终止时导致的极少数
NullPointerException
问题。
版本 1.0.0-alpha03
2022 年 12 月 7 日
发布了 androidx.javascriptengine:javascriptengine:1.0.0-alpha03
。版本 1.0.0-alpha03 中包含这些提交内容。
新功能
- 内存不足所导致的崩溃包含在负责任的隔离中,而不是使整个沙盒崩溃。隔离一旦耗尽内存,便无法用于进一步的评估。
- 目前,在沙盒关闭前,系统不会释放隔离所占用的资源。此资源释放行为可能会在更高版本的库中发生变化。
API 变更
- 当评估导致隔离内存不足时抛出
MemoryLimitExceededException
。(I336ca)
版本 1.0.0-alpha02
2022 年 10 月 5 日
发布了 androidx.javascriptengine:javascriptengine:1.0.0-alpha02
。版本 1.0.0-alpha02 中包含这些提交内容。
新功能
- 添加了
JavaScriptSandbox#isSupported
,用于检查系统是否支持 JavaScript 沙盒。
API 变更
- 由于缺少系统支持而无法创建
JavaScriptSandbox
时,会抛出 SandboxUnsupportedException
。(I0dcd6)
版本 1.0.0-alpha01
2022 年 8 月 10 日
发布了 androidx.javascriptengine:javascriptengine:1.0.0-alpha01
。版本 1.0.0-alpha01 中包含这些提交内容。
新功能
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# JavascriptEngine\n================\n\nAPI Reference \n[androidx.javascriptengine](/reference/kotlin/androidx/javascriptengine/package-summary) \nEnable your Android app to evaluate JavaScript. \n\n| Latest Update | Stable Release | Release Candidate | Beta Release | Alpha Release |\n|---------------|------------------------------------------------------------|-------------------|--------------|---------------|\n| July 2, 2025 | [1.0.0](/jetpack/androidx/releases/javascriptengine#1.0.0) | - | - | - |\n\nDeclaring dependencies\n----------------------\n\nTo add a dependency on JavascriptEngine, you must add the Google Maven repository to your\nproject. Read [Google's Maven repository](/studio/build/dependencies#google-maven)\nfor more information.\n\nAdd the dependencies for the artifacts you need in the `build.gradle` file for\nyour app or module: \n\n### Groovy\n\n```groovy\ndependencies {\n implementation \"androidx.javascriptengine:javascriptengine:1.0.0\"\n}\n```\n\n### Kotlin\n\n```kotlin\ndependencies {\n implementation(\"androidx.javascriptengine:javascriptengine:1.0.0\")\n}\n```\n\nFor more information about dependencies, see [Add build dependencies](/studio/build/dependencies).\n\nFeedback\n--------\n\nYour feedback helps make Jetpack better. Let us know if you discover new issues or have\nideas for improving this library. Please take a look at the\n[existing issues](https://issuetracker.google.com/issues?q=componentid:1225213%20status:open)\nin this library before you create a new one. You can add your vote to an existing issue by\nclicking the star button.\n\n[Create a new issue](https://issuetracker.google.com/issues/new?component=1225213&template=1720664)\n\nSee the [Issue Tracker documentation](https://developers.google.com/issue-tracker)\nfor more information.\n\nVersion 1.0\n-----------\n\n### Version 1.0.0\n\nJuly 2, 2025\n\n`androidx.javascriptengine:javascriptengine:1.0.0` is released with no notable changes since the last rc release. Version 1.0.0 contains [these commits](https://android.googlesource.com/platform/frameworks/support/+log/82c11d1adf6b4e2a93f8c52f42398ae45d6fe7ae..87de50e190d7e843166cedd9df75192e999fe84b/javascriptengine/javascriptengine).\n\n### Version 1.0.0-rc01\n\nMarch 26, 2025\n\n`androidx.javascriptengine:javascriptengine:1.0.0-rc01` is released with no notable changes since the last beta. Version 1.0.0-rc01 contains [these commits](https://android.googlesource.com/platform/frameworks/support/+log/e3ffd7948030a769c857b8c629e0079c54b730ad..82c11d1adf6b4e2a93f8c52f42398ae45d6fe7ae/javascriptengine/javascriptengine).\n\n### Version 1.0.0-beta01\n\nNovember 1, 2023\n\n`androidx.javascriptengine:javascriptengine:1.0.0-beta01` is released with no notable changes since hte last alpha. [Version 1.0.0-beta01 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/465c5c5b7a0d79793bddb26a695f67aba8ea2f7e..e3ffd7948030a769c857b8c629e0079c54b730ad/javascriptengine/javascriptengine)\n\n### Version 1.0.0-alpha07\n\nOctober 18, 2023\n\n`androidx.javascriptengine:javascriptengine:1.0.0-alpha07` is released. [Version 1.0.0-alpha07 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/1f7407d4293384a1b91bc142880e3525048b3443..465c5c5b7a0d79793bddb26a695f67aba8ea2f7e/javascriptengine/javascriptengine)\n\n**New Features**\n\n- New API introduced to allow apps to register callbacks to handle isolate crashes.\n\n**API Changes**\n\n- Rename `DEFAULT_MAX_HEAP_SIZE` to `AUTOMATIC_MAX_HEAP_SIZE`. ([I6d303](https://android-review.googlesource.com/#/q/I6d303f359434c90c338f0ded308356ee61f11ca3))\n- Rename `FileDescriptorIoException` to `DataInputException`. ([Iba4eb](https://android-review.googlesource.com/#/q/Iba4ebd392f3e4ca7c0a4831a1a76fa5635a78596))\n- Rename `DEFAULT_ISOLATE_HEAP_SIZE` to `DEFAULT_MAX_HEAP_SIZE`. ([Iaa16f](https://android-review.googlesource.com/#/q/Iaa16f8fc099012b135f13197fa8e4a012cd57f5f))\n- Remove non-functional console `getSource` and `getTrace` methods. ([I4b7a2](https://android-review.googlesource.com/#/q/I4b7a2102ee682e52f23b4ec54dbd5647038fb551))\n- Unhide `FileDescriptorIoException` ([Ic44e6](https://android-review.googlesource.com/#/q/Ic44e678260c450190fcac70d4ceb8886f667ea52))\n- Allow apps to register callbacks to handle isolate crashes. ([Iad25f](https://android-review.googlesource.com/#/q/Iad25f63f60fa8fc8be6d60af89e40c97ab2b469d))\n\n### Version 1.0.0-alpha06\n\nOctober 4, 2023\n\n`androidx.javascriptengine:javascriptengine:1.0.0-alpha06` is released. [Version 1.0.0-alpha06 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/a200cb82769634cecdb118ec4f0bfdf0b086e597..1f7407d4293384a1b91bc142880e3525048b3443/javascriptengine/javascriptengine)\n\n**New Features**\n\n- New API introduced to evaluate JavaScript from a `ParcelFileDescriptor/AssetFileDescriptor` without the need to convert the source into a String. `JavaScriptIsolate` class is made thread-safe.\n\n**API Changes**\n\n- Change `provideNamedData` to throw exception instead of returning false. ([I8909a](https://android-review.googlesource.com/#/q/I8909ad16dd777c5458855a86e817360d6a7f81d1))\n- Adding APIs for evaluating JavaScript through Afds and Pfds ([I03e3a](https://android-review.googlesource.com/#/q/I03e3a8e00a990e1205853e8d8e825f605c4ebbd4))\n- Make `MemoryLimitExceededException` and `SandboxDeadException` subclass `IsolateTerminatedException` ([Icf359](https://android-review.googlesource.com/#/q/Icf359de9cc83d63b376bf77b31c7873b04ba59dc))\n- Removing public facing API `evaluateJavaScriptAsync(@NonNull byte[] code)` ([I4b3ac](https://android-review.googlesource.com/#/q/I4b3ac9406ada38bb5845ec3e230e3d42013ae4f9))\n\n**Bug Fixes**\n\n- Make `JavaScriptIsolate` thread safe. ([Ib28e0](https://android-review.googlesource.com/#/q/Ib28e00f5b7744bb4557786246d588b9273a30596))\n\n### Version 1.0.0-alpha05\n\nApril 5, 2023\n\n`androidx.javascriptengine:javascriptengine:1.0.0-alpha05` is released. [Version 1.0.0-alpha05 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/1ab1efa5be7608eac6f3d4ba7f0aae6df7df2f3e..a200cb82769634cecdb118ec4f0bfdf0b086e597/javascriptengine/javascriptengine)\n\n**API Changes**\n\n- Evaluation and result are no longer bound by Binder limits ([I13b1d](https://android-review.googlesource.com/#/q/I13b1d446c96925918ecd751243d8feb5d1f56faf))\n- Add callback for handling isolate console messages ([I11725](https://android-review.googlesource.com/#/q/I11725004167d148c3e3b001fd0799fb4f2030253), [Ic1c11](https://android-review.googlesource.com/#/q/Ic1c110e9f7fe9cb146bd711aebefb9505a473142))\n\n### Version 1.0.0-alpha04\n\nFebruary 22, 2023\n\n`androidx.javascriptengine:javascriptengine:1.0.0-alpha04` is released. [Version 1.0.0-alpha04 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/4a2f5e696614339c1ac21f706c1a17c0285780e7..1ab1efa5be7608eac6f3d4ba7f0aae6df7df2f3e/javascriptengine/javascriptengine)\n\n**Bug Fixes**\n\n- Fixes a rare case of `NullPointerException` caused when the sandboxed process dies.\n\n### Version 1.0.0-alpha03\n\nDecember 7, 2022\n\n`androidx.javascriptengine:javascriptengine:1.0.0-alpha03` is released. [Version 1.0.0-alpha03 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/4586cf6e518f0c59410ef2b291e34ff9fdcff4e1..4a2f5e696614339c1ac21f706c1a17c0285780e7/javascriptengine/javascriptengine)\n\n**New Features**\n\n- Contain out of memory crashes to the responsible isolate instead of crashing the entire sandbox. Once the isolate goes out of memory, it cannot be used for further evaluation.\n- Currently, the resources that the isolate holds are not freed till the sandbox is closed. This resource freeing behavior might change in later versions of the library.\n\n**API Changes**\n\n- Throw `MemoryLimitExceededException` when an evaluation leads to isolate going out of memory.([I336ca](https://android-review.googlesource.com/#/q/I336cae281670ed2a75e57a67cb2103cc8a722147))\n\n### Version 1.0.0-alpha02\n\nOctober 5, 2022\n\n`androidx.javascriptengine:javascriptengine:1.0.0-alpha02` is released. [Version 1.0.0-alpha02 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/bea814b246f89ff7244e3c6b0648f0b57e47897c..4586cf6e518f0c59410ef2b291e34ff9fdcff4e1/javascriptengine/javascriptengine)\n\n**New Features**\n\n- Add `JavaScriptSandbox#isSupported` for checking whether the system supports JavaScript sandboxes.\n\n**API Changes**\n\n- Throw `SandboxUnsupportedException` when `JavaScriptSandbox` cannot be created due to lack of system support. ([I0dcd6](https://android-review.googlesource.com/#/q/I0dcd6f577ce55fdede9cad8c3dfb48905169f8e5))\n\n### Version 1.0.0-alpha01\n\nAugust 10, 2022\n\n`androidx.javascriptengine:javascriptengine:1.0.0-alpha01` is released. [Version 1.0.0-alpha01 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/bea814b246f89ff7244e3c6b0648f0b57e47897c/javascriptengine/javascriptengine)\n\n**New Features**\n\n- We've added experimental support for `JavaScriptSandbox` and `JavaScriptIsolate` to enable clients to evaluate JavaScript in a safe and restricted environment. This is an area of active development; the APIs are subject to change without notice.\n\n- Please file feature requests and bugs our [JavascriptEngine component](https://issuetracker.google.com/issues/new?component=1225213&template=1720664)!"]]