透過集合功能整理內容
你可以依據偏好儲存及分類內容。
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")
}
如要進一步瞭解依附元件,請參閱「新增建構依附元件」一文。
意見回饋
您的意見可協助我們改善 Jetpack。如果您發現新問題,或是有改進這個程式庫的建議,請告訴我們。回報新問題前,請先查看這個程式庫的現有問題。只要按一下星號按鈕,即可投票給現有的問題。
建立新問題
詳情請參閱 Issue Tracker 說明文件。
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)
- 新增 API,透過 Afds 和 Pfds 評估 JavaScript (I03e3a)
- 將
MemoryLimitExceededException
和 SandboxDeadException
設為 IsolateTerminatedException
的子類別 (Icf359)
- 移除面向大眾的 API
evaluateJavaScriptAsync(@NonNull byte[] code)
(I4b3ac)
修正錯誤
- 讓
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 版的修訂項。
修正錯誤
- 修正沙箱程序失敗時導致的極少數
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 和/或其關係企業的商標或註冊商標。
上次更新時間: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"]],["上次更新時間: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)!"]]